svn_hash.h

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

Generated on Mon Nov 2 11:07:59 2015 for Subversion by  doxygen 1.4.7