apr_hash.inc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. { Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. }
  16. {
  17. * @file apr_hash.h
  18. * @brief APR Hash Tables
  19. }
  20. //#include "apr_pools.h"
  21. {
  22. * @defgroup apr_hash Hash Tables
  23. * @ingroup APR
  24. * @
  25. }
  26. {
  27. * When passing a key to apr_hash_set or apr_hash_get, this value can be
  28. * passed to indicate a string-valued key, and have apr_hash compute the
  29. * length automatically.
  30. *
  31. * @remark apr_hash will use strlen(key) for the length. The null-terminator
  32. * is not included in the hash value (why throw a constant in?).
  33. * Since the hash table merely references the provided key (rather
  34. * than copying it), apr_hash_this() will return the null-term'd key.
  35. }
  36. const
  37. APR_HASH_KEY_STRING = -1;
  38. {
  39. * Abstract type for hash tables.
  40. }
  41. type
  42. apr_hash_t = record end;
  43. Papr_hash_t = ^apr_hash_t;
  44. {
  45. * Abstract type for scanning hash tables.
  46. }
  47. apr_hash_index_t = record end;
  48. Papr_hash_index_t = ^apr_hash_index_t;
  49. {
  50. * Callback functions for calculating hash values.
  51. * @param key The key.
  52. * @param klen The length of the key, or APR_HASH_KEY_STRING to use the string
  53. * length. If APR_HASH_KEY_STRING then returns the actual key length.
  54. }
  55. apr_hashfunc_t = function (const key: PChar; klen: Papr_size_t): cuint;
  56. {
  57. * The default hash function.
  58. }
  59. function apr_hashfunc_default(const key: PChar; klen: Papr_size_t): cuint;
  60. cdecl; external LibAPR name 'apr_hashfunc_default';
  61. {
  62. * Create a hash table.
  63. * @param pool The pool to allocate the hash table out of
  64. * @return The hash table just created
  65. }
  66. function apr_hash_make(pool: Papr_pool_t): Papr_hash_t;
  67. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  68. external LibAPR name LibNamePrefix + 'apr_hash_make' + LibSuff4;
  69. {
  70. * Create a hash table with a custom hash function
  71. * @param pool The pool to allocate the hash table out of
  72. * @param hash_func A custom hash function.
  73. * @return The hash table just created
  74. }
  75. function apr_hash_make_custom(pool: Papr_pool_t; hash_func: apr_hashfunc_t): Papr_hash_t;
  76. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  77. external LibAPR name LibNamePrefix + 'apr_hash_make_custom' + LibSuff8;
  78. {
  79. * Make a copy of a hash table
  80. * @param pool The pool from which to allocate the new hash table
  81. * @param h The hash table to clone
  82. * @return The hash table just created
  83. * @remark Makes a shallow copy
  84. }
  85. function apr_hash_copy(pool: Papr_pool_t; const h: Papr_hash_t): Papr_hash_t;
  86. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  87. external LibAPR name LibNamePrefix + 'apr_hash_copy' + LibSuff8;
  88. {
  89. * Associate a value with a key in a hash table.
  90. * @param ht The hash table
  91. * @param key Pointer to the key
  92. * @param klen Length of the key. Can be APR_HASH_KEY_STRING to use the string length.
  93. * @param val Value to associate with the key
  94. * @remark If the value is NULL the hash entry is deleted.
  95. }
  96. procedure apr_hash_set(ht: Papr_hash_t; const key: Pointer;
  97. klen: apr_size_t; const val: Pointer);
  98. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  99. external LibAPR name LibNamePrefix + 'apr_hash_set' + LibSuff16;
  100. {
  101. * Look up the value associated with a key in a hash table.
  102. * @param ht The hash table
  103. * @param key Pointer to the key
  104. * @param klen Length of the key. Can be APR_HASH_KEY_STRING to use the string length.
  105. * @return Returns NULL if the key is not present.
  106. }
  107. function apr_hash_get(ht: Papr_hash_t; const key: Pointer;
  108. klen: apr_size_t): Pointer;
  109. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  110. external LibAPR name LibNamePrefix + 'apr_hash_get' + LibSuff12;
  111. {
  112. * Start iterating over the entries in a hash table.
  113. * @param p The pool to allocate the apr_hash_index_t iterator. If this
  114. * pool is NULL, then an internal, non-thread-safe iterator is used.
  115. * @param ht The hash table
  116. * @remark There is no restriction on adding or deleting hash entries during
  117. * an iteration (although the results may be unpredictable unless all you do
  118. * is delete the current entry) and multiple iterations can be in
  119. * progress at the same time.
  120. * @example
  121. }
  122. {
  123. * <PRE>
  124. *
  125. * int sum_values(apr_pool_t *p, apr_hash_t *ht)
  126. * (
  127. * apr_hash_index_t *hi;
  128. * void *val;
  129. * int sum = 0;
  130. * for (hi = apr_hash_first(p, ht); hi; hi = apr_hash_next(hi)) (
  131. * apr_hash_this(hi, NULL, NULL, &val);
  132. * sum += *(int * )val;
  133. * )
  134. * return sum;
  135. * )
  136. * </PRE>
  137. }
  138. function apr_hash_first(p: Papr_pool_t; ht: Papr_hash_t): Papr_hash_index_t;
  139. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  140. external LibAPR name LibNamePrefix + 'apr_hash_first' + LibSuff8;
  141. {
  142. * Continue iterating over the entries in a hash table.
  143. * @param hi The iteration state
  144. * @return a pointer to the updated iteration state. NULL if there are no more
  145. * entries.
  146. }
  147. function apr_hash_next(hi: Papr_hash_index_t): Papr_hash_index_t;
  148. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  149. external LibAPR name LibNamePrefix + 'apr_hash_next' + LibSuff4;
  150. {
  151. * Get the current entry's details from the iteration state.
  152. * @param hi The iteration state
  153. * @param key Return pointer for the pointer to the key.
  154. * @param klen Return pointer for the key length.
  155. * @param val Return pointer for the associated value.
  156. * @remark The return pointers should point to a variable that will be set to the
  157. * corresponding data, or they may be NULL if the data isn't interesting.
  158. }
  159. procedure apr_hash_this(hi: Papr_hash_index_t; const key: PPointer;
  160. klen: Papr_size_t; val: PPointer);
  161. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  162. external LibAPR name LibNamePrefix + 'apr_hash_this' + LibSuff16;
  163. {
  164. * Get the number of key/value pairs in the hash table.
  165. * @param ht The hash table
  166. * @return The number of key/value pairs in the hash table.
  167. }
  168. function apr_hash_count(ht: Papr_hash_t): cuint;
  169. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  170. external LibAPR name LibNamePrefix + 'apr_hash_count' + LibSuff4;
  171. {
  172. * Merge two hash tables into one new hash table. The values of the overlay
  173. * hash override the values of the base if both have the same key. Both
  174. * hash tables must use the same hash function.
  175. * @param p The pool to use for the new hash table
  176. * @param overlay The table to add to the initial table
  177. * @param base The table that represents the initial values of the new table
  178. * @return A new hash table containing all of the data from the two passed in
  179. }
  180. function apr_hash_overlay(p: Papr_pool_t;
  181. const overlay, base: Papr_hash_t): Papr_hash_t;
  182. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  183. external LibAPR name LibNamePrefix + 'apr_hash_overlay' + LibSuff12;
  184. {
  185. * Merge two hash tables into one new hash table. If the same key
  186. * is present in both tables, call the supplied merge function to
  187. * produce a merged value for the key in the new table. Both
  188. * hash tables must use the same hash function.
  189. * @param p The pool to use for the new hash table
  190. * @param h1 The first of the tables to merge
  191. * @param h2 The second of the tables to merge
  192. * @param merger A callback function to merge values, or NULL to
  193. * make values from h1 override values from h2 (same semantics as
  194. * apr_hash_overlay())
  195. * @param data Client data to pass to the merger function
  196. * @return A new hash table containing all of the data from the two passed in
  197. }
  198. type
  199. apr_hash_merge_t = function (p: Papr_pool_t; const key: Pointer; klen: apr_size_t;
  200. const h1_val, h2_val, data: Pointer): Pointer; cdecl;
  201. function apr_hash_merge(p: Papr_pool_t;
  202. const h1, h2: Papr_hash_t;
  203. merger: apr_hash_merge_t; const data: Pointer): Papr_hash_t;
  204. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  205. external LibAPR name LibNamePrefix + 'apr_hash_merge' + LibSuff20;
  206. {
  207. * Get a pointer to the pool which the hash table was created in
  208. }
  209. //APR_POOL_DECLARE_ACCESSOR(hash);