svn_hash.h

Go to the documentation of this file.
00001 /**
00002  * @copyright
00003  * ====================================================================
00004  * Copyright (c) 2000-2004, 2008 CollabNet.  All rights reserved.
00005  *
00006  * This software is licensed as described in the file COPYING, which
00007  * you should have received as part of this distribution.  The terms
00008  * are also available at http://subversion.tigris.org/license-1.html.
00009  * If newer versions of this license are posted there, you may use a
00010  * newer version instead, at your option.
00011  *
00012  * This software consists of voluntary contributions made by many
00013  * individuals.  For exact contribution history, see the revision
00014  * history and logs, available at http://subversion.tigris.org/.
00015  * ====================================================================
00016  * @endcopyright
00017  *
00018  * @file svn_hash.h
00019  * @brief Dumping and reading hash tables to/from files.
00020  */
00021 
00022 
00023 #ifndef SVN_HASH_H
00024 #define SVN_HASH_H
00025 
00026 #include <apr_pools.h>
00027 #include <apr_hash.h>
00028 #include <apr_file_io.h>
00029 
00030 #include "svn_types.h"
00031 #include "svn_io.h"
00032 #include "svn_error.h"
00033 
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif /* __cplusplus */
00038 
00039 
00040 /** The longest the "K <number>" line can be in one of our hashdump files. */
00041 #define SVN_KEYLINE_MAXLEN 100
00042 
00043 /**
00044  * @defgroup svn_hash_support Hash table serialization support
00045  * @{
00046  */
00047 
00048 /*----------------------------------------------------*/
00049 
00050 /** Reading/writing hashtables to disk
00051  *
00052  * @defgroup svn_hash_read_write Reading and writing hashtables to disk
00053  * @{
00054  */
00055 
00056 /**
00057  * The conventional terminator for hash dumps.
00058  *
00059  * @since New in 1.1.
00060  */
00061 #define SVN_HASH_TERMINATOR "END"
00062 
00063 /**
00064  * Read a hash table from @a stream, storing the resultants names and
00065  * values in @a hash.  Use a @a pool for all allocations.  @a hash will
00066  * have <tt>const char *</tt> keys and <tt>svn_string_t *</tt> values.
00067  * If @a terminator is NULL, expect the hash to be terminated by the
00068  * end of the stream; otherwise, expect the hash to be terminated by a
00069  * line containing @a terminator.  Pass @c SVN_HASH_TERMINATOR to use
00070  * the conventional terminator "END".
00071  *
00072  * @since New in 1.1.
00073  */
00074 svn_error_t *
00075 svn_hash_read2(apr_hash_t *hash,
00076                svn_stream_t *stream,
00077                const char *terminator,
00078                apr_pool_t *pool);
00079 
00080 /**
00081  * Dump @a hash to @a stream.  Use @a pool for all allocations.  @a
00082  * hash has <tt>const char *</tt> keys and <tt>svn_string_t *</tt>
00083  * values.  If @a terminator is not NULL, terminate the hash with a
00084  * line containing @a terminator.
00085  *
00086  * @since New in 1.1.
00087  */
00088 svn_error_t *
00089 svn_hash_write2(apr_hash_t *hash,
00090                 svn_stream_t *stream,
00091                 const char *terminator,
00092                 apr_pool_t *pool);
00093 
00094 /**
00095  * Similar to svn_hash_read2(), but allows @a stream to contain
00096  * deletion lines which remove entries from @a hash as well as adding
00097  * to it.
00098  *
00099  * @since New in 1.1.
00100  */
00101 svn_error_t *
00102 svn_hash_read_incremental(apr_hash_t *hash,
00103                           svn_stream_t *stream,
00104                           const char *terminator,
00105                           apr_pool_t *pool);
00106 
00107 /**
00108  * Similar to svn_hash_write2(), but only writes out entries for
00109  * keys which differ between @a hash and @a oldhash, and also writes
00110  * out deletion lines for keys which are present in @a oldhash but not
00111  * in @a hash.
00112  *
00113  * @since New in 1.1.
00114  */
00115 svn_error_t *
00116 svn_hash_write_incremental(apr_hash_t *hash,
00117                            apr_hash_t *oldhash,
00118                            svn_stream_t *stream,
00119                            const char *terminator,
00120                            apr_pool_t *pool);
00121 
00122 /**
00123  * This function behaves like svn_hash_read2(), but it only works
00124  * on an apr_file_t input, empty files are accepted, and the hash is
00125  * expected to be terminated with a line containing "END" or
00126  * "PROPS-END".
00127  *
00128  * @deprecated Provided for backward compatibility with the 1.0 API.
00129  */
00130 SVN_DEPRECATED
00131 svn_error_t *
00132 svn_hash_read(apr_hash_t *hash,
00133               apr_file_t *srcfile,
00134               apr_pool_t *pool);
00135 
00136 /**
00137  * This function behaves like svn_hash_write2(), but it only works
00138  * on an apr_file_t output, and the terminator is always "END".
00139  *
00140  * @deprecated Provided for backward compatibility with the 1.0 API.
00141  */
00142 SVN_DEPRECATED
00143 svn_error_t *
00144 svn_hash_write(apr_hash_t *hash,
00145                apr_file_t *destfile,
00146                apr_pool_t *pool);
00147 
00148 /** @} */
00149 
00150 
00151 /** Taking the "diff" of two hash tables.
00152  *
00153  * @defgroup svn_hash_diff Taking the diff of two hash tables.
00154  * @{
00155  */
00156 
00157 /** Hash key status indicator for svn_hash_diff_func_t.  */
00158 enum svn_hash_diff_key_status
00159   {
00160     /* Key is present in both hashes. */
00161     svn_hash_diff_key_both,
00162 
00163     /* Key is present in first hash only. */
00164     svn_hash_diff_key_a,
00165 
00166     /* Key is present in second hash only. */
00167     svn_hash_diff_key_b
00168   };
00169 
00170 
00171 /** Function type for expressing a key's status between two hash tables. */
00172 typedef svn_error_t *(*svn_hash_diff_func_t)
00173   (const void *key, apr_ssize_t klen,
00174    enum svn_hash_diff_key_status status,
00175    void *baton);
00176 
00177 
00178 /** Take the diff of two hashtables.
00179  *
00180  * For each key in the union of @a hash_a's and @a hash_b's keys, invoke
00181  * @a diff_func exactly once, passing the key, the key's length, an enum
00182  * @c svn_hash_diff_key_status indicating which table(s) the key appears
00183  * in, and @a diff_func_baton.
00184  *
00185  * Process all keys of @a hash_a first, then all remaining keys of @a hash_b.
00186  *
00187  * If @a diff_func returns error, return that error immediately, without
00188  * applying @a diff_func to anything else.
00189  *
00190  * @a hash_a or @a hash_b or both may be NULL; treat a null table as though
00191  * empty.
00192  *
00193  * Use @a pool for temporary allocation.
00194  */
00195 svn_error_t *
00196 svn_hash_diff(apr_hash_t *hash_a,
00197               apr_hash_t *hash_b,
00198               svn_hash_diff_func_t diff_func,
00199               void *diff_func_baton,
00200               apr_pool_t *pool);
00201 
00202 /** @} */
00203 
00204 
00205 /**
00206  * @defgroup svn_hash_misc Miscellaneous hash APIs
00207  * @{
00208  */
00209 
00210 /**
00211  * Return the keys to @a hash in @a *array.  The keys are assumed to be
00212  * (const char *).  The keys are in no particular order.
00213  *
00214  * @a *array itself is allocated in @a pool; however, the keys are not
00215  * copied from the hash.
00216  *
00217  * @since New in 1.5.
00218  */
00219 svn_error_t *
00220 svn_hash_keys(apr_array_header_t **array,
00221               apr_hash_t *hash,
00222               apr_pool_t *pool);
00223 
00224 /**
00225  * Set @a *hash to a new hash whose keys come from the items in @a keys
00226  * (an array of <tt>const char *</tt> items), and whose values are
00227  * match their corresponding key.  Use @a pool for all allocations
00228  * (including @a *hash, its keys, and its values).
00229  *
00230  * @since New in 1.5.
00231  */
00232 svn_error_t *
00233 svn_hash_from_cstring_keys(apr_hash_t **hash,
00234                            const apr_array_header_t *keys,
00235                            apr_pool_t *pool);
00236 
00237 /**
00238  * Clear any key/value pairs in the hash table.  A wrapper for a
00239  * apr_hash_clear(), which isn't available until APR 1.3.0.
00240  *
00241  * @since New in 1.5.
00242  */
00243 svn_error_t *
00244 svn_hash__clear(apr_hash_t *hash);
00245 
00246 /** @} */
00247 
00248 /** @} */
00249 
00250 #ifdef __cplusplus
00251 }
00252 #endif /* __cplusplus */
00253 
00254 #endif /* SVN_HASH_H */

Generated on Tue Oct 7 04:09:55 2008 for Subversion by  doxygen 1.3.9.1