3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
20 * ====================================================================
24 * @brief Dumping and reading hash tables to/from files.
32 #include <apr_pools.h>
34 #include <apr_tables.h>
35 #include <apr_file_io.h> /* for apr_file_t */
37 #include "svn_types.h"
38 #include "svn_io.h" /* for svn_stream_t */
42 #endif /* __cplusplus */
45 /** The longest the "K <number>" line can be in one of our hashdump files. */
46 #define SVN_KEYLINE_MAXLEN 100
49 * @defgroup svn_hash_support Hash table serialization support
53 /*----------------------------------------------------*/
55 /** Reading/writing hashtables to disk
57 * @defgroup svn_hash_read_write Reading and writing hashtables to disk
62 * The conventional terminator for hash dumps.
66 #define SVN_HASH_TERMINATOR "END"
69 * Read a hash table from @a stream, storing the resultants names and
70 * values in @a hash. Use a @a pool for all allocations. @a hash will
71 * have <tt>const char *</tt> keys and <tt>svn_string_t *</tt> values.
72 * If @a terminator is NULL, expect the hash to be terminated by the
73 * end of the stream; otherwise, expect the hash to be terminated by a
74 * line containing @a terminator. Pass @c SVN_HASH_TERMINATOR to use
75 * the conventional terminator "END".
80 svn_hash_read2(apr_hash_t *hash,
82 const char *terminator,
86 * Dump @a hash to @a stream. Use @a pool for all allocations. @a
87 * hash has <tt>const char *</tt> keys and <tt>svn_string_t *</tt>
88 * values. If @a terminator is not NULL, terminate the hash with a
89 * line containing @a terminator.
94 svn_hash_write2(apr_hash_t *hash,
96 const char *terminator,
100 * Similar to svn_hash_read2(), but allows @a stream to contain
101 * deletion lines which remove entries from @a hash as well as adding
107 svn_hash_read_incremental(apr_hash_t *hash,
108 svn_stream_t *stream,
109 const char *terminator,
113 * Similar to svn_hash_write2(), but only writes out entries for
114 * keys which differ between @a hash and @a oldhash, and also writes
115 * out deletion lines for keys which are present in @a oldhash but not
121 svn_hash_write_incremental(apr_hash_t *hash,
123 svn_stream_t *stream,
124 const char *terminator,
128 * This function behaves like svn_hash_read2(), but it only works
129 * on an apr_file_t input, empty files are accepted, and the hash is
130 * expected to be terminated with a line containing "END" or
133 * @deprecated Provided for backward compatibility with the 1.0 API.
137 svn_hash_read(apr_hash_t *hash,
142 * This function behaves like svn_hash_write2(), but it only works
143 * on an apr_file_t output, and the terminator is always "END".
145 * @deprecated Provided for backward compatibility with the 1.0 API.
149 svn_hash_write(apr_hash_t *hash,
150 apr_file_t *destfile,
156 /** Taking the "diff" of two hash tables.
158 * @defgroup svn_hash_diff Taking the diff of two hash tables.
162 /** Hash key status indicator for svn_hash_diff_func_t. */
163 enum svn_hash_diff_key_status
165 /* Key is present in both hashes. */
166 svn_hash_diff_key_both,
168 /* Key is present in first hash only. */
171 /* Key is present in second hash only. */
176 /** Function type for expressing a key's status between two hash tables. */
177 typedef svn_error_t *(*svn_hash_diff_func_t)
178 (const void *key, apr_ssize_t klen,
179 enum svn_hash_diff_key_status status,
183 /** Take the diff of two hashtables.
185 * For each key in the union of @a hash_a's and @a hash_b's keys, invoke
186 * @a diff_func exactly once, passing the key, the key's length, an enum
187 * @c svn_hash_diff_key_status indicating which table(s) the key appears
188 * in, and @a diff_func_baton.
190 * Process all keys of @a hash_a first, then all remaining keys of @a hash_b.
192 * If @a diff_func returns error, return that error immediately, without
193 * applying @a diff_func to anything else.
195 * @a hash_a or @a hash_b or both may be NULL; treat a null table as though
198 * Use @a pool for temporary allocation.
201 svn_hash_diff(apr_hash_t *hash_a,
203 svn_hash_diff_func_t diff_func,
204 void *diff_func_baton,
211 * @defgroup svn_hash_misc Miscellaneous hash APIs
216 * Return the keys to @a hash in @a *array. The keys are assumed to be
217 * (const char *). The keys are in no particular order.
219 * @a *array itself is allocated in @a pool; however, the keys are not
220 * copied from the hash.
225 svn_hash_keys(apr_array_header_t **array,
230 * Set @a *hash to a new hash whose keys come from the items in @a keys
231 * (an array of <tt>const char *</tt> items), and whose values are
232 * match their corresponding key. Use @a pool for all allocations
233 * (including @a *hash, its keys, and its values).
238 svn_hash_from_cstring_keys(apr_hash_t **hash,
239 const apr_array_header_t *keys,
242 /** Shortcut for apr_hash_get() with a const char * key.
246 #define svn_hash_gets(ht, key) \
247 apr_hash_get(ht, key, APR_HASH_KEY_STRING)
249 /** Shortcut for apr_hash_set() with a const char * key.
253 #define svn_hash_sets(ht, key, val) \
254 apr_hash_set(ht, key, APR_HASH_KEY_STRING, val)
262 #endif /* __cplusplus */
264 #endif /* SVN_HASH_H */