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 */
43 #endif /* __cplusplus */
46 /** The longest the "K <number>" line can be in one of our hashdump files. */
47 #define SVN_KEYLINE_MAXLEN 100
50 * @defgroup svn_hash_support Hash table serialization support
54 /*----------------------------------------------------*/
56 /** Reading/writing hashtables to disk
58 * @defgroup svn_hash_read_write Reading and writing hashtables to disk
63 * The conventional terminator for hash dumps.
67 #define SVN_HASH_TERMINATOR "END"
70 * Read a hash table from @a stream, storing the resultants names and
71 * values in @a hash. Use a @a pool for all allocations. @a hash will
72 * have <tt>const char *</tt> keys and <tt>svn_string_t *</tt> values.
73 * If @a terminator is NULL, expect the hash to be terminated by the
74 * end of the stream; otherwise, expect the hash to be terminated by a
75 * line containing @a terminator. Pass @c SVN_HASH_TERMINATOR to use
76 * the conventional terminator "END".
81 svn_hash_read2(apr_hash_t
*hash
,
83 const char *terminator
,
87 * Dump @a hash to @a stream. Use @a pool for all allocations. @a
88 * hash has <tt>const char *</tt> keys and <tt>svn_string_t *</tt>
89 * values. If @a terminator is not NULL, terminate the hash with a
90 * line containing @a terminator.
95 svn_hash_write2(apr_hash_t
*hash
,
97 const char *terminator
,
101 * Similar to svn_hash_read2(), but allows @a stream to contain
102 * deletion lines which remove entries from @a hash as well as adding
108 svn_hash_read_incremental(apr_hash_t
*hash
,
109 svn_stream_t
*stream
,
110 const char *terminator
,
114 * Similar to svn_hash_write2(), but only writes out entries for
115 * keys which differ between @a hash and @a oldhash, and also writes
116 * out deletion lines for keys which are present in @a oldhash but not
122 svn_hash_write_incremental(apr_hash_t
*hash
,
124 svn_stream_t
*stream
,
125 const char *terminator
,
129 * This function behaves like svn_hash_read2(), but it only works
130 * on an apr_file_t input, empty files are accepted, and the hash is
131 * expected to be terminated with a line containing "END" or
134 * @deprecated Provided for backward compatibility with the 1.0 API.
138 svn_hash_read(apr_hash_t
*hash
,
143 * This function behaves like svn_hash_write2(), but it only works
144 * on an apr_file_t output, and the terminator is always "END".
146 * @deprecated Provided for backward compatibility with the 1.0 API.
150 svn_hash_write(apr_hash_t
*hash
,
151 apr_file_t
*destfile
,
157 /** Taking the "diff" of two hash tables.
159 * @defgroup svn_hash_diff Taking the diff of two hash tables.
163 /** Hash key status indicator for svn_hash_diff_func_t. */
164 enum svn_hash_diff_key_status
166 /* Key is present in both hashes. */
167 svn_hash_diff_key_both
,
169 /* Key is present in first hash only. */
172 /* Key is present in second hash only. */
177 /** Function type for expressing a key's status between two hash tables. */
178 typedef svn_error_t
*(*svn_hash_diff_func_t
)
179 (const void *key
, apr_ssize_t klen
,
180 enum svn_hash_diff_key_status status
,
184 /** Take the diff of two hashtables.
186 * For each key in the union of @a hash_a's and @a hash_b's keys, invoke
187 * @a diff_func exactly once, passing the key, the key's length, an enum
188 * @c svn_hash_diff_key_status indicating which table(s) the key appears
189 * in, and @a diff_func_baton.
191 * Process all keys of @a hash_a first, then all remaining keys of @a hash_b.
193 * If @a diff_func returns error, return that error immediately, without
194 * applying @a diff_func to anything else.
196 * @a hash_a or @a hash_b or both may be NULL; treat a null table as though
199 * Use @a pool for temporary allocation.
202 svn_hash_diff(apr_hash_t
*hash_a
,
204 svn_hash_diff_func_t diff_func
,
205 void *diff_func_baton
,
212 * @defgroup svn_hash_misc Miscellaneous hash APIs
217 * Return the keys to @a hash in @a *array. The keys are assumed to be
218 * (const char *). The keys are in no particular order.
220 * @a *array itself is allocated in @a pool; however, the keys are not
221 * copied from the hash.
226 svn_hash_keys(apr_array_header_t
**array
,
231 * Set @a *hash to a new hash whose keys come from the items in @a keys
232 * (an array of <tt>const char *</tt> items), and whose values are
233 * match their corresponding key. Use @a pool for all allocations
234 * (including @a *hash, its keys, and its values).
239 svn_hash_from_cstring_keys(apr_hash_t
**hash
,
240 const apr_array_header_t
*keys
,
243 /* Shortcut for apr_hash_get() with a const char * key.
247 #define svn_hash_gets(ht, key) \
248 apr_hash_get(ht, key, APR_HASH_KEY_STRING)
250 /* Shortcut for apr_hash_set() with a const char * key.
254 #define svn_hash_sets(ht, key, val) \
255 apr_hash_set(ht, key, APR_HASH_KEY_STRING, val)
263 #endif /* __cplusplus */
265 #endif /* SVN_HASH_H */