<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Apache Portable Runtime: apr_hash.h Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.3.9.1 --> <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> <div class="nav"> <a class="el" href="dir_000000.html">home</a> / <a class="el" href="dir_000001.html">oden</a> / <a class="el" href="dir_000002.html">RPM</a> / <a class="el" href="dir_000003.html">BUILD</a> / <a class="el" href="dir_000004.html">apr-1.1.1</a> / <a class="el" href="dir_000005.html">include</a></div> <h1>apr_hash.h</h1><a href="apr__hash_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/* Copyright 2000-2004 The Apache Software Foundation</span> 00002 <span class="comment"> *</span> 00003 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span> 00004 <span class="comment"> * you may not use this file except in compliance with the License.</span> 00005 <span class="comment"> * You may obtain a copy of the License at</span> 00006 <span class="comment"> *</span> 00007 <span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span> 00008 <span class="comment"> *</span> 00009 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span> 00010 <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span> 00011 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> 00012 <span class="comment"> * See the License for the specific language governing permissions and</span> 00013 <span class="comment"> * limitations under the License.</span> 00014 <span class="comment"> */</span> 00015 00016 <span class="preprocessor">#ifndef APR_HASH_H</span> 00017 <span class="preprocessor"></span><span class="preprocessor">#define APR_HASH_H</span> 00018 <span class="preprocessor"></span><span class="comment"></span> 00019 <span class="comment">/**</span> 00020 <span class="comment"> * @file apr_hash.h</span> 00021 <span class="comment"> * @brief APR Hash Tables</span> 00022 <span class="comment"> */</span> 00023 00024 <span class="preprocessor">#include "<a class="code" href="apr__pools_8h.html">apr_pools.h</a>"</span> 00025 00026 <span class="preprocessor">#ifdef __cplusplus</span> 00027 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">"C"</span> { 00028 <span class="preprocessor">#endif</span> 00029 <span class="preprocessor"></span><span class="comment"></span> 00030 <span class="comment">/**</span> 00031 <span class="comment"> * @defgroup apr_hash Hash Tables</span> 00032 <span class="comment"> * @ingroup APR </span> 00033 <span class="comment"> * @{</span> 00034 <span class="comment"> */</span> 00035 <span class="comment"></span> 00036 <span class="comment">/**</span> 00037 <span class="comment"> * When passing a key to apr_hash_set or apr_hash_get, this value can be</span> 00038 <span class="comment"> * passed to indicate a string-valued key, and have apr_hash compute the</span> 00039 <span class="comment"> * length automatically.</span> 00040 <span class="comment"> *</span> 00041 <span class="comment"> * @remark apr_hash will use strlen(key) for the length. The NUL terminator</span> 00042 <span class="comment"> * is not included in the hash value (why throw a constant in?).</span> 00043 <span class="comment"> * Since the hash table merely references the provided key (rather</span> 00044 <span class="comment"> * than copying it), apr_hash_this() will return the NUL-term'd key.</span> 00045 <span class="comment"> */</span> <a name="l00046"></a><a class="code" href="group__apr__hash.html#ga16">00046</a> <span class="preprocessor">#define APR_HASH_KEY_STRING (-1)</span> 00047 <span class="preprocessor"></span><span class="comment"></span> 00048 <span class="comment">/**</span> 00049 <span class="comment"> * Abstract type for hash tables.</span> 00050 <span class="comment"> */</span> <a name="l00051"></a><a class="code" href="group__apr__hash.html#ga0">00051</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="group__apr__hash.html#ga0">apr_hash_t</a> <a class="code" href="group__apr__hash.html#ga0">apr_hash_t</a>; 00052 <span class="comment"></span> 00053 <span class="comment">/**</span> 00054 <span class="comment"> * Abstract type for scanning hash tables.</span> 00055 <span class="comment"> */</span> <a name="l00056"></a><a class="code" href="group__apr__hash.html#ga1">00056</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="group__apr__hash.html#ga1">apr_hash_index_t</a> <a class="code" href="group__apr__hash.html#ga1">apr_hash_index_t</a>; 00057 <span class="comment"></span> 00058 <span class="comment">/**</span> 00059 <span class="comment"> * Callback functions for calculating hash values.</span> 00060 <span class="comment"> * @param key The key.</span> 00061 <span class="comment"> * @param klen The length of the key, or APR_HASH_KEY_STRING to use the string </span> 00062 <span class="comment"> * length. If APR_HASH_KEY_STRING then returns the actual key length.</span> 00063 <span class="comment"> */</span> <a name="l00064"></a><a class="code" href="group__apr__hash.html#ga2">00064</a> <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> int (*apr_hashfunc_t)(<span class="keyword">const</span> <span class="keywordtype">char</span> *key, apr_ssize_t *klen); 00065 <span class="comment"></span> 00066 <span class="comment">/**</span> 00067 <span class="comment"> * The default hash function.</span> 00068 <span class="comment"> */</span> 00069 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="group__apr__hash.html#ga3">apr_hashfunc_default</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *key, apr_ssize_t *klen); 00070 <span class="comment"></span> 00071 <span class="comment">/**</span> 00072 <span class="comment"> * Create a hash table.</span> 00073 <span class="comment"> * @param pool The pool to allocate the hash table out of</span> 00074 <span class="comment"> * @return The hash table just created</span> 00075 <span class="comment"> */</span> 00076 <a class="code" href="group__apr__platform.html#ga123">APR_DECLARE</a>(apr_hash_t *) apr_hash_make(apr_pool_t *pool); 00077 <span class="comment"></span> 00078 <span class="comment">/**</span> 00079 <span class="comment"> * Create a hash table with a custom hash function</span> 00080 <span class="comment"> * @param pool The pool to allocate the hash table out of</span> 00081 <span class="comment"> * @param hash_func A custom hash function.</span> 00082 <span class="comment"> * @return The hash table just created</span> 00083 <span class="comment"> */</span> 00084 APR_DECLARE(apr_hash_t *) apr_hash_make_custom(apr_pool_t *pool, 00085 apr_hashfunc_t hash_func); 00086 <span class="comment"></span> 00087 <span class="comment">/**</span> 00088 <span class="comment"> * Make a copy of a hash table</span> 00089 <span class="comment"> * @param pool The pool from which to allocate the new hash table</span> 00090 <span class="comment"> * @param h The hash table to clone</span> 00091 <span class="comment"> * @return The hash table just created</span> 00092 <span class="comment"> * @remark Makes a shallow copy</span> 00093 <span class="comment"> */</span> 00094 APR_DECLARE(apr_hash_t *) apr_hash_copy(apr_pool_t *pool, 00095 const apr_hash_t *h); 00096 <span class="comment"></span> 00097 <span class="comment">/**</span> 00098 <span class="comment"> * Associate a value with a key in a hash table.</span> 00099 <span class="comment"> * @param ht The hash table</span> 00100 <span class="comment"> * @param key Pointer to the key</span> 00101 <span class="comment"> * @param klen Length of the key. Can be APR_HASH_KEY_STRING to use the string length.</span> 00102 <span class="comment"> * @param val Value to associate with the key</span> 00103 <span class="comment"> * @remark If the value is NULL the hash entry is deleted.</span> 00104 <span class="comment"> */</span> 00105 APR_DECLARE(<span class="keywordtype">void</span>) apr_hash_set(apr_hash_t *ht, const <span class="keywordtype">void</span> *key, 00106 apr_ssize_t klen, const <span class="keywordtype">void</span> *val); 00107 <span class="comment"></span> 00108 <span class="comment">/**</span> 00109 <span class="comment"> * Look up the value associated with a key in a hash table.</span> 00110 <span class="comment"> * @param ht The hash table</span> 00111 <span class="comment"> * @param key Pointer to the key</span> 00112 <span class="comment"> * @param klen Length of the key. Can be APR_HASH_KEY_STRING to use the string length.</span> 00113 <span class="comment"> * @return Returns NULL if the key is not present.</span> 00114 <span class="comment"> */</span> 00115 APR_DECLARE(<span class="keywordtype">void</span> *) apr_hash_get(apr_hash_t *ht, const <span class="keywordtype">void</span> *key, 00116 apr_ssize_t klen); 00117 <span class="comment"></span> 00118 <span class="comment">/**</span> 00119 <span class="comment"> * Start iterating over the entries in a hash table.</span> 00120 <span class="comment"> * @param p The pool to allocate the apr_hash_index_t iterator. If this</span> 00121 <span class="comment"> * pool is NULL, then an internal, non-thread-safe iterator is used.</span> 00122 <span class="comment"> * @param ht The hash table</span> 00123 <span class="comment"> * @remark There is no restriction on adding or deleting hash entries during</span> 00124 <span class="comment"> * an iteration (although the results may be unpredictable unless all you do</span> 00125 <span class="comment"> * is delete the current entry) and multiple iterations can be in</span> 00126 <span class="comment"> * progress at the same time.</span> 00127 <span class="comment"></span> 00128 <span class="comment"> * @example</span> 00129 <span class="comment"> */</span><span class="comment"></span> 00130 <span class="comment">/**</span> 00131 <span class="comment"> * <PRE></span> 00132 <span class="comment"> * </span> 00133 <span class="comment"> * int sum_values(apr_pool_t *p, apr_hash_t *ht)</span> 00134 <span class="comment"> * {</span> 00135 <span class="comment"> * apr_hash_index_t *hi;</span> 00136 <span class="comment"> * void *val;</span> 00137 <span class="comment"> * int sum = 0;</span> 00138 <span class="comment"> * for (hi = apr_hash_first(p, ht); hi; hi = apr_hash_next(hi)) {</span> 00139 <span class="comment"> * apr_hash_this(hi, NULL, NULL, &val);</span> 00140 <span class="comment"> * sum += *(int *)val;</span> 00141 <span class="comment"> * }</span> 00142 <span class="comment"> * return sum;</span> 00143 <span class="comment"> * }</span> 00144 <span class="comment"> * </PRE></span> 00145 <span class="comment"> */</span> 00146 APR_DECLARE(apr_hash_index_t *) apr_hash_first(apr_pool_t *p, apr_hash_t *ht); 00147 <span class="comment"></span> 00148 <span class="comment">/**</span> 00149 <span class="comment"> * Continue iterating over the entries in a hash table.</span> 00150 <span class="comment"> * @param hi The iteration state</span> 00151 <span class="comment"> * @return a pointer to the updated iteration state. NULL if there are no more </span> 00152 <span class="comment"> * entries.</span> 00153 <span class="comment"> */</span> 00154 APR_DECLARE(apr_hash_index_t *) apr_hash_next(apr_hash_index_t *hi); 00155 <span class="comment"></span> 00156 <span class="comment">/**</span> 00157 <span class="comment"> * Get the current entry's details from the iteration state.</span> 00158 <span class="comment"> * @param hi The iteration state</span> 00159 <span class="comment"> * @param key Return pointer for the pointer to the key.</span> 00160 <span class="comment"> * @param klen Return pointer for the key length.</span> 00161 <span class="comment"> * @param val Return pointer for the associated value.</span> 00162 <span class="comment"> * @remark The return pointers should point to a variable that will be set to the</span> 00163 <span class="comment"> * corresponding data, or they may be NULL if the data isn't interesting.</span> 00164 <span class="comment"> */</span> 00165 APR_DECLARE(<span class="keywordtype">void</span>) apr_hash_this(apr_hash_index_t *hi, const <span class="keywordtype">void</span> **key, 00166 apr_ssize_t *klen, <span class="keywordtype">void</span> **val); 00167 <span class="comment"></span> 00168 <span class="comment">/**</span> 00169 <span class="comment"> * Get the number of key/value pairs in the hash table.</span> 00170 <span class="comment"> * @param ht The hash table</span> 00171 <span class="comment"> * @return The number of key/value pairs in the hash table.</span> 00172 <span class="comment"> */</span> 00173 APR_DECLARE(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>) apr_hash_count(apr_hash_t *ht); 00174 <span class="comment"></span> 00175 <span class="comment">/**</span> 00176 <span class="comment"> * Merge two hash tables into one new hash table. The values of the overlay</span> 00177 <span class="comment"> * hash override the values of the base if both have the same key. Both</span> 00178 <span class="comment"> * hash tables must use the same hash function.</span> 00179 <span class="comment"> * @param p The pool to use for the new hash table</span> 00180 <span class="comment"> * @param overlay The table to add to the initial table</span> 00181 <span class="comment"> * @param base The table that represents the initial values of the new table</span> 00182 <span class="comment"> * @return A new hash table containing all of the data from the two passed in</span> 00183 <span class="comment"> */</span> 00184 APR_DECLARE(apr_hash_t *) apr_hash_overlay(apr_pool_t *p, 00185 const apr_hash_t *overlay, 00186 const apr_hash_t *base); 00187 <span class="comment"></span> 00188 <span class="comment">/**</span> 00189 <span class="comment"> * Merge two hash tables into one new hash table. If the same key</span> 00190 <span class="comment"> * is present in both tables, call the supplied merge function to</span> 00191 <span class="comment"> * produce a merged value for the key in the new table. Both</span> 00192 <span class="comment"> * hash tables must use the same hash function.</span> 00193 <span class="comment"> * @param p The pool to use for the new hash table</span> 00194 <span class="comment"> * @param h1 The first of the tables to merge</span> 00195 <span class="comment"> * @param h2 The second of the tables to merge</span> 00196 <span class="comment"> * @param merger A callback function to merge values, or NULL to</span> 00197 <span class="comment"> * make values from h1 override values from h2 (same semantics as</span> 00198 <span class="comment"> * apr_hash_overlay())</span> 00199 <span class="comment"> * @param data Client data to pass to the merger function</span> 00200 <span class="comment"> * @return A new hash table containing all of the data from the two passed in</span> 00201 <span class="comment"> */</span> 00202 APR_DECLARE(apr_hash_t *) apr_hash_merge(apr_pool_t *p, 00203 const apr_hash_t *h1, 00204 const apr_hash_t *h2, 00205 <span class="keywordtype">void</span> * (*merger)(apr_pool_t *p, 00206 const <span class="keywordtype">void</span> *key, 00207 apr_ssize_t klen, 00208 const <span class="keywordtype">void</span> *h1_val, 00209 const <span class="keywordtype">void</span> *h2_val, 00210 const <span class="keywordtype">void</span> *data), 00211 const <span class="keywordtype">void</span> *data); 00212 <span class="comment"></span> 00213 <span class="comment">/**</span> 00214 <span class="comment"> * Get a pointer to the pool which the hash table was created in</span> 00215 <span class="comment"> */</span> 00216 APR_POOL_DECLARE_ACCESSOR(hash); 00217 <span class="comment"></span> 00218 <span class="comment">/** @} */</span> 00219 00220 #ifdef __cplusplus 00221 } 00222 #endif 00223 00224 #endif <span class="comment">/* !APR_HASH_H */</span> </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Mar 20 19:52:26 2005 for Apache Portable Runtime by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address> </body> </html>