3 * ====================================================================
4 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
19 * @brief Dumping and reading hash tables to/from files.
26 #include <apr_pools.h>
28 #include <apr_file_io.h>
30 #include "svn_types.h"
32 #include "svn_error.h"
37 #endif /* __cplusplus */
40 /** The longest the "K <number>" line can be in one of our hashdump files. */
41 #define SVN_KEYLINE_MAXLEN 100
44 * @defgroup svn_hash_support Hash table serialization support
48 /*----------------------------------------------------*/
50 /** Reading/writing hashtables to disk
52 * @defgroup svn_hash_read_write Reading and writing hashtables to disk
57 * The conventional terminator for hash dumps.
61 #define SVN_HASH_TERMINATOR "END"
64 * Read a hash table from @a stream, storing the resultants names and
65 * values in @a hash. Use a @a pool for all allocations. @a hash will
66 * have <tt>const char *</tt> keys and <tt>svn_string_t *</tt> values.
67 * If @a terminator is NULL, expect the hash to be terminated by the
68 * end of the stream; otherwise, expect the hash to be terminated by a
69 * line containing @a terminator. Pass @c SVN_HASH_TERMINATOR to use
70 * the conventional terminator "END".
74 svn_error_t
*svn_hash_read2(apr_hash_t
*hash
,
76 const char *terminator
,
80 * Dump @a hash to @a stream. Use @a pool for all allocations. @a
81 * hash has <tt>const char *</tt> keys and <tt>svn_string_t *</tt>
82 * values. If @a terminator is not NULL, terminate the hash with a
83 * line containing @a terminator.
87 svn_error_t
*svn_hash_write2(apr_hash_t
*hash
,
89 const char *terminator
,
93 * Similar to svn_hash_read2(), but allows @a stream to contain
94 * deletion lines which remove entries from @a hash as well as adding
99 svn_error_t
*svn_hash_read_incremental(apr_hash_t
*hash
,
100 svn_stream_t
*stream
,
101 const char *terminator
,
105 * Similar to svn_hash_write2(), but only writes out entries for
106 * keys which differ between @a hash and @a oldhash, and also writes
107 * out deletion lines for keys which are present in @a oldhash but not
112 svn_error_t
*svn_hash_write_incremental(apr_hash_t
*hash
,
114 svn_stream_t
*stream
,
115 const char *terminator
,
119 * This function behaves like svn_hash_read2(), but it only works
120 * on an apr_file_t input, empty files are accepted, and the hash is
121 * expected to be terminated with a line containing "END" or
124 * @deprecated Provided for backward compatibility with the 1.0 API.
126 svn_error_t
*svn_hash_read(apr_hash_t
*hash
,
131 * This function behaves like svn_hash_write2(), but it only works
132 * on an apr_file_t output, and the terminator is always "END".
134 * @deprecated Provided for backward compatibility with the 1.0 API.
136 svn_error_t
*svn_hash_write(apr_hash_t
*hash
,
137 apr_file_t
*destfile
,
143 /** Taking the "diff" of two hash tables.
145 * @defgroup svn_hash_diff Taking the diff of two hash tables.
149 /** Hash key status indicator for svn_hash_diff_func_t. */
150 enum svn_hash_diff_key_status
152 /* Key is present in both hashes. */
153 svn_hash_diff_key_both
,
155 /* Key is present in first hash only. */
158 /* Key is present in second hash only. */
163 /** Function type for expressing a key's status between two hash tables. */
164 typedef svn_error_t
*(*svn_hash_diff_func_t
)
165 (const void *key
, apr_ssize_t klen
,
166 enum svn_hash_diff_key_status status
,
170 /** Take the diff of two hashtables.
172 * For each key in the union of @a hash_a's and @a hash_b's keys, invoke
173 * @a diff_func exactly once, passing the key, the key's length, an enum
174 * @c svn_hash_diff_key_status indicating which table(s) the key appears
175 * in, and @a diff_func_baton.
177 * Process all keys of @a hash_a first, then all remaining keys of @a hash_b.
179 * If @a diff_func returns error, return that error immediately, without
180 * applying @a diff_func to anything else.
182 * @a hash_a or @a hash_b or both may be NULL; treat a null table as though
185 * Use @a pool for temporary allocation.
187 svn_error_t
*svn_hash_diff(apr_hash_t
*hash_a
,
189 svn_hash_diff_func_t diff_func
,
190 void *diff_func_baton
,
197 * @defgroup svn_hash_misc Miscellaneous hash APIs
202 * Return the keys to @a hash in @a *array. The keys are assumed to be
203 * (const char *). The keys are in no particular order.
205 * @a *array itself is allocated in @a pool; however, the keys are not
206 * copied from the hash.
210 svn_error_t
*svn_hash_keys(apr_array_header_t
**array
,
215 * Set @a *hash to a new hash whose keys come from the items in @a keys
216 * (an array of <tt>const char *</tt> items), and whose values are
217 * match their corresponding key. Use @a pool for all allocations
218 * (including @a *hash, its keys, and its values).
222 svn_error_t
*svn_hash_from_cstring_keys(apr_hash_t
**hash
,
223 const apr_array_header_t
*keys
,
227 * Clear any key/value pairs in the hash table. A wrapper for a
228 * apr_hash_clear(), which isn't available until APR 1.3.0.
232 svn_error_t
*svn_hash__clear(apr_hash_t
*hash
);
240 #endif /* __cplusplus */
242 #endif /* SVN_HASH_H */