apr_hash.inc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. * Create a hash table.
  51. * @param pool The pool to allocate the hash table out of
  52. * @return The hash table just created
  53. }
  54. function apr_hash_make(pool: Papr_pool_t): Papr_hash_t;
  55. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  56. external LibAPR name LibNamePrefix + 'apr_hash_make' + LibSuff4;
  57. {
  58. * Make a copy of a hash table
  59. * @param pool The pool from which to allocate the new hash table
  60. * @param h The hash table to clone
  61. * @return The hash table just created
  62. * @remark Makes a shallow copy
  63. }
  64. function apr_hash_copy(pool: Papr_pool_t; const h: Papr_hash_t): Papr_hash_t;
  65. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  66. external LibAPR name LibNamePrefix + 'apr_hash_copy' + LibSuff8;
  67. {
  68. * Associate a value with a key in a hash table.
  69. * @param ht The hash table
  70. * @param key Pointer to the key
  71. * @param klen Length of the key. Can be APR_HASH_KEY_STRING to use the string length.
  72. * @param val Value to associate with the key
  73. * @remark If the value is NULL the hash entry is deleted.
  74. }
  75. procedure apr_hash_set(ht: Papr_hash_t; const key: Pointer;
  76. klen: apr_size_t; const val: Pointer);
  77. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  78. external LibAPR name LibNamePrefix + 'apr_hash_set' + LibSuff16;
  79. {
  80. * Look up the value associated with a key in a hash table.
  81. * @param ht The hash table
  82. * @param key Pointer to the key
  83. * @param klen Length of the key. Can be APR_HASH_KEY_STRING to use the string length.
  84. * @return Returns NULL if the key is not present.
  85. }
  86. function apr_hash_get(ht: Papr_hash_t; const key: Pointer;
  87. klen: apr_size_t): Pointer;
  88. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  89. external LibAPR name LibNamePrefix + 'apr_hash_get' + LibSuff12;
  90. {
  91. * Start iterating over the entries in a hash table.
  92. * @param p The pool to allocate the apr_hash_index_t iterator. If this
  93. * pool is NULL, then an internal, non-thread-safe iterator is used.
  94. * @param ht The hash table
  95. * @remark There is no restriction on adding or deleting hash entries during
  96. * an iteration (although the results may be unpredictable unless all you do
  97. * is delete the current entry) and multiple iterations can be in
  98. * progress at the same time.
  99. * @example
  100. }
  101. {
  102. * <PRE>
  103. *
  104. * int sum_values(apr_pool_t *p, apr_hash_t *ht)
  105. * (
  106. * apr_hash_index_t *hi;
  107. * void *val;
  108. * int sum = 0;
  109. * for (hi = apr_hash_first(p, ht); hi; hi = apr_hash_next(hi)) (
  110. * apr_hash_this(hi, NULL, NULL, &val);
  111. * sum += *(int * )val;
  112. * )
  113. * return sum;
  114. * )
  115. * </PRE>
  116. }
  117. function apr_hash_first(p: Papr_pool_t; ht: Papr_hash_t): Papr_hash_index_t;
  118. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  119. external LibAPR name LibNamePrefix + 'apr_hash_first' + LibSuff8;
  120. {
  121. * Continue iterating over the entries in a hash table.
  122. * @param hi The iteration state
  123. * @return a pointer to the updated iteration state. NULL if there are no more
  124. * entries.
  125. }
  126. function apr_hash_next(hi: Papr_hash_index_t): Papr_hash_index_t;
  127. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  128. external LibAPR name LibNamePrefix + 'apr_hash_next' + LibSuff4;
  129. {
  130. * Get the current entry's details from the iteration state.
  131. * @param hi The iteration state
  132. * @param key Return pointer for the pointer to the key.
  133. * @param klen Return pointer for the key length.
  134. * @param val Return pointer for the associated value.
  135. * @remark The return pointers should point to a variable that will be set to the
  136. * corresponding data, or they may be NULL if the data isn't interesting.
  137. }
  138. procedure apr_hash_this(hi: Papr_hash_index_t; const key: PPointer;
  139. klen: Papr_size_t; val: PPointer);
  140. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  141. external LibAPR name LibNamePrefix + 'apr_hash_this' + LibSuff16;
  142. {
  143. * Get the number of key/value pairs in the hash table.
  144. * @param ht The hash table
  145. * @return The number of key/value pairs in the hash table.
  146. }
  147. function apr_hash_count(ht: Papr_hash_t): cuint;
  148. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  149. external LibAPR name LibNamePrefix + 'apr_hash_count' + LibSuff4;
  150. {
  151. * Merge two hash tables into one new hash table. The values of the overlay
  152. * hash override the values of the base if both have the same key.
  153. * @param p The pool to use for the new hash table
  154. * @param overlay The table to add to the initial table
  155. * @param base The table that represents the initial values of the new table
  156. * @return A new hash table containing all of the data from the two passed in
  157. }
  158. function apr_hash_overlay(p: Papr_pool_t;
  159. const overlay, base: Papr_hash_t): Papr_hash_t;
  160. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  161. external LibAPR name LibNamePrefix + 'apr_hash_overlay' + LibSuff12;
  162. {
  163. * Merge two hash tables into one new hash table. If the same key
  164. * is present in both tables, call the supplied merge function to
  165. * produce a merged value for the key in the new table.
  166. * @param p The pool to use for the new hash table
  167. * @param h1 The first of the tables to merge
  168. * @param h2 The second of the tables to merge
  169. * @param merger A callback function to merge values, or NULL to
  170. * make values from h1 override values from h2 (same semantics as
  171. * apr_hash_overlay())
  172. * @param data Client data to pass to the merger function
  173. * @return A new hash table containing all of the data from the two passed in
  174. }
  175. type
  176. apr_hash_merge_t = function (p: Papr_pool_t; const key: Pointer; klen: apr_size_t;
  177. const h1_val, h2_val, data: Pointer): Pointer; cdecl;
  178. function apr_hash_merge(p: Papr_pool_t;
  179. const h1, h2: Papr_hash_t;
  180. merger: apr_hash_merge_t; const data: Pointer): Papr_hash_t;
  181. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  182. external LibAPR name LibNamePrefix + 'apr_hash_merge' + LibSuff20;
  183. {
  184. * Get a pointer to the pool which the hash table was created in
  185. }
  186. //APR_POOL_DECLARE_ACCESSOR(hash);