Subversion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
svn_hash.h
Go to the documentation of this file.
1 /**
2  * @copyright
3  * ====================================================================
4  * Copyright (c) 2000-2004, 2008 CollabNet. All rights reserved.
5  *
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.
11  *
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  * ====================================================================
16  * @endcopyright
17  *
18  * @file svn_hash.h
19  * @brief Dumping and reading hash tables to/from files.
20  */
21 
22 
23 #ifndef SVN_HASH_H
24 #define SVN_HASH_H
25 
26 #include <apr.h>
27 #include <apr_pools.h>
28 #include <apr_hash.h>
29 #include <apr_tables.h>
30 #include <apr_file_io.h> /* for apr_file_t */
31 
32 #include "svn_types.h"
33 #include "svn_io.h" /* for svn_stream_t */
34 
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39 
40 
41 /** The longest the "K <number>" line can be in one of our hashdump files. */
42 #define SVN_KEYLINE_MAXLEN 100
43 
44 /**
45  * @defgroup svn_hash_support Hash table serialization support
46  * @{
47  */
48 
49 /*----------------------------------------------------*/
50 
51 /** Reading/writing hashtables to disk
52  *
53  * @defgroup svn_hash_read_write Reading and writing hashtables to disk
54  * @{
55  */
56 
57 /**
58  * The conventional terminator for hash dumps.
59  *
60  * @since New in 1.1.
61  */
62 #define SVN_HASH_TERMINATOR "END"
63 
64 /**
65  * Read a hash table from @a stream, storing the resultants names and
66  * values in @a hash. Use a @a pool for all allocations. @a hash will
67  * have <tt>const char *</tt> keys and <tt>svn_string_t *</tt> values.
68  * If @a terminator is NULL, expect the hash to be terminated by the
69  * end of the stream; otherwise, expect the hash to be terminated by a
70  * line containing @a terminator. Pass @c SVN_HASH_TERMINATOR to use
71  * the conventional terminator "END".
72  *
73  * @since New in 1.1.
74  */
76 svn_hash_read2(apr_hash_t *hash,
77  svn_stream_t *stream,
78  const char *terminator,
79  apr_pool_t *pool);
80 
81 /**
82  * Dump @a hash to @a stream. Use @a pool for all allocations. @a
83  * hash has <tt>const char *</tt> keys and <tt>svn_string_t *</tt>
84  * values. If @a terminator is not NULL, terminate the hash with a
85  * line containing @a terminator.
86  *
87  * @since New in 1.1.
88  */
90 svn_hash_write2(apr_hash_t *hash,
91  svn_stream_t *stream,
92  const char *terminator,
93  apr_pool_t *pool);
94 
95 /**
96  * Similar to svn_hash_read2(), but allows @a stream to contain
97  * deletion lines which remove entries from @a hash as well as adding
98  * to it.
99  *
100  * @since New in 1.1.
101  */
102 svn_error_t *
103 svn_hash_read_incremental(apr_hash_t *hash,
104  svn_stream_t *stream,
105  const char *terminator,
106  apr_pool_t *pool);
107 
108 /**
109  * Similar to svn_hash_write2(), but only writes out entries for
110  * keys which differ between @a hash and @a oldhash, and also writes
111  * out deletion lines for keys which are present in @a oldhash but not
112  * in @a hash.
113  *
114  * @since New in 1.1.
115  */
116 svn_error_t *
117 svn_hash_write_incremental(apr_hash_t *hash,
118  apr_hash_t *oldhash,
119  svn_stream_t *stream,
120  const char *terminator,
121  apr_pool_t *pool);
122 
123 /**
124  * This function behaves like svn_hash_read2(), but it only works
125  * on an apr_file_t input, empty files are accepted, and the hash is
126  * expected to be terminated with a line containing "END" or
127  * "PROPS-END".
128  *
129  * @deprecated Provided for backward compatibility with the 1.0 API.
130  */
132 svn_error_t *
133 svn_hash_read(apr_hash_t *hash,
134  apr_file_t *srcfile,
135  apr_pool_t *pool);
136 
137 /**
138  * This function behaves like svn_hash_write2(), but it only works
139  * on an apr_file_t output, and the terminator is always "END".
140  *
141  * @deprecated Provided for backward compatibility with the 1.0 API.
142  */
144 svn_error_t *
145 svn_hash_write(apr_hash_t *hash,
146  apr_file_t *destfile,
147  apr_pool_t *pool);
148 
149 /** @} */
150 
151 
152 /** Taking the "diff" of two hash tables.
153  *
154  * @defgroup svn_hash_diff Taking the diff of two hash tables.
155  * @{
156  */
157 
158 /** Hash key status indicator for svn_hash_diff_func_t. */
160  {
161  /* Key is present in both hashes. */
162  svn_hash_diff_key_both,
163 
164  /* Key is present in first hash only. */
165  svn_hash_diff_key_a,
166 
167  /* Key is present in second hash only. */
168  svn_hash_diff_key_b
169  };
170 
171 
172 /** Function type for expressing a key's status between two hash tables. */
173 typedef svn_error_t *(*svn_hash_diff_func_t)
174  (const void *key, apr_ssize_t klen,
175  enum svn_hash_diff_key_status status,
176  void *baton);
177 
178 
179 /** Take the diff of two hashtables.
180  *
181  * For each key in the union of @a hash_a's and @a hash_b's keys, invoke
182  * @a diff_func exactly once, passing the key, the key's length, an enum
183  * @c svn_hash_diff_key_status indicating which table(s) the key appears
184  * in, and @a diff_func_baton.
185  *
186  * Process all keys of @a hash_a first, then all remaining keys of @a hash_b.
187  *
188  * If @a diff_func returns error, return that error immediately, without
189  * applying @a diff_func to anything else.
190  *
191  * @a hash_a or @a hash_b or both may be NULL; treat a null table as though
192  * empty.
193  *
194  * Use @a pool for temporary allocation.
195  */
196 svn_error_t *
197 svn_hash_diff(apr_hash_t *hash_a,
198  apr_hash_t *hash_b,
199  svn_hash_diff_func_t diff_func,
200  void *diff_func_baton,
201  apr_pool_t *pool);
202 
203 /** @} */
204 
205 
206 /**
207  * @defgroup svn_hash_misc Miscellaneous hash APIs
208  * @{
209  */
210 
211 /**
212  * Return the keys to @a hash in @a *array. The keys are assumed to be
213  * (const char *). The keys are in no particular order.
214  *
215  * @a *array itself is allocated in @a pool; however, the keys are not
216  * copied from the hash.
217  *
218  * @since New in 1.5.
219  */
220 svn_error_t *
221 svn_hash_keys(apr_array_header_t **array,
222  apr_hash_t *hash,
223  apr_pool_t *pool);
224 
225 /**
226  * Set @a *hash to a new hash whose keys come from the items in @a keys
227  * (an array of <tt>const char *</tt> items), and whose values are
228  * match their corresponding key. Use @a pool for all allocations
229  * (including @a *hash, its keys, and its values).
230  *
231  * @since New in 1.5.
232  */
233 svn_error_t *
234 svn_hash_from_cstring_keys(apr_hash_t **hash,
235  const apr_array_header_t *keys,
236  apr_pool_t *pool);
237 
238 /**
239  * Clear any key/value pairs in the hash table. A wrapper for a
240  * apr_hash_clear(), which isn't available until APR 1.3.0.
241  *
242  * @since New in 1.5.
243  */
244 svn_error_t *
245 svn_hash__clear(apr_hash_t *hash);
246 
247 /** @} */
248 
249 /** @} */
250 
251 #ifdef __cplusplus
252 }
253 #endif /* __cplusplus */
254 
255 #endif /* SVN_HASH_H */