Skip to content
Newer
Older
100644 349 lines (289 sloc) 14.6 KB
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
2c5d4b8 @sebastianbergmann Bump year.
sebastianbergmann authored Dec 31, 2002
5 | Copyright (c) 1998-2003 Zend Technologies Ltd. (http://www.zend.com) |
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
6 +----------------------------------------------------------------------+
d863d52 @sebastianbergmann Update headers.
sebastianbergmann authored Dec 11, 2001
7 | This source file is subject to version 2.00 of the Zend license, |
b5b1117 @zsuraski License update
zsuraski authored Jul 16, 1999
8 | that is bundled with this package in the file LICENSE, and is |
f68c7ff updating license information in the headers.
James Cox authored Jun 10, 2003
9 | available through the world-wide-web at the following url: |
d863d52 @sebastianbergmann Update headers.
sebastianbergmann authored Dec 11, 2001
10 | http://www.zend.com/license/2_00.txt. |
b5b1117 @zsuraski License update
zsuraski authored Jul 16, 1999
11 | If you did not receive a copy of the Zend license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@zend.com so we can mail you a copy immediately. |
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 +----------------------------------------------------------------------+
18 */
19
333406b - Added some missing CVS $Id$ tags, headers and footers.
foobar authored Feb 1, 2003
20 /* $Id$ */
21
a617217 Replace macros which begin with an underscore through an appropiately
Sascha Schumann authored Jul 3, 2000
22 #ifndef ZEND_HASH_H
23 #define ZEND_HASH_H
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
24
25 #include <sys/types.h>
90f43c7 @andigutmans - This should improve performance on Windows
andigutmans authored Jun 8, 2002
26 #include "zend.h"
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
27
28 #define HASH_KEY_IS_STRING 1
29 #define HASH_KEY_IS_LONG 2
30 #define HASH_KEY_NON_EXISTANT 3
31
32 #define HASH_UPDATE (1<<0)
33 #define HASH_ADD (1<<1)
34 #define HASH_NEXT_INSERT (1<<2)
35
36 #define HASH_DEL_KEY 0
37 #define HASH_DEL_INDEX 1
38
2f8fa8c @andigutmans - Merge faster hash implementation.
andigutmans authored Jul 10, 2001
39 typedef ulong (*hash_func_t)(char *arKey, uint nKeyLength);
3bdddb4 @sebastianbergmann MFZE1
sebastianbergmann authored Sep 19, 2001
40 typedef int (*compare_func_t)(const void *, const void * TSRMLS_DC);
41 typedef void (*sort_func_t)(void *, size_t, register size_t, compare_func_t TSRMLS_DC);
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored Jan 17, 2000
42 typedef void (*dtor_func_t)(void *pDest);
9f51f15 @zsuraski - Stop passing list/plist to internal functions
zsuraski authored Feb 5, 2000
43 typedef void (*copy_ctor_func_t)(void *pElement);
e062dff @zsuraski - Implement public/protected/private methods.
zsuraski authored Dec 6, 2002
44 typedef void (*copy_ctor_param_func_t)(void *pElement, void *pParam);
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored Jan 17, 2000
45
9b916e6 rename hastable -> _hashtable to avoid clashes
Thies C. Arntzen authored May 24, 2000
46 struct _hashtable;
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
47
48 typedef struct bucket {
49 ulong h; /* Used for numeric indexing */
50 uint nKeyLength;
51 void *pData;
52 void *pDataPtr;
53 struct bucket *pListNext;
54 struct bucket *pListLast;
55 struct bucket *pNext;
aa73f6b @andigutmans - Hopefully fix the hash problem.
andigutmans authored Jan 19, 2000
56 struct bucket *pLast;
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
57 char arKey[1]; /* Must be last element */
58 } Bucket;
59
9b916e6 rename hastable -> _hashtable to avoid clashes
Thies C. Arntzen authored May 24, 2000
60 typedef struct _hashtable {
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
61 uint nTableSize;
2f8fa8c @andigutmans - Merge faster hash implementation.
andigutmans authored Jul 10, 2001
62 uint nTableMask;
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
63 uint nNumOfElements;
64 ulong nNextFreeElement;
65 Bucket *pInternalPointer; /* Used for element traversal */
66 Bucket *pListHead;
67 Bucket *pListTail;
68 Bucket **arBuckets;
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored Jan 17, 2000
69 dtor_func_t pDestructor;
38cdb8e @zsuraski Avoid crashing with recursive applies - limit apply nest level to 3 (…
zsuraski authored Jun 17, 2000
70 zend_bool persistent;
71 unsigned char nApplyCount;
1263932 @zsuraski Disable the hash_apply() protection on hashes that persist across req…
zsuraski authored Jul 11, 2000
72 zend_bool bApplyProtection;
c93a189 if ZEND_DEBUG mode is on we'll now see warnings when a HashTable is a…
Thies C. Arntzen authored Jan 15, 2000
73 #if ZEND_DEBUG
74 int inconsistent;
75 #endif
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
76 } HashTable;
77
471947b @zsuraski Reimplement PPP properties
zsuraski authored Feb 4, 2003
78
79 typedef struct _zend_hash_key {
80 char *arKey;
81 uint nKeyLength;
82 ulong h;
83 } zend_hash_key;
84
85
45c1235 @zsuraski Fix prototype (may have caused stack corruption)
zsuraski authored Feb 6, 2003
86 typedef zend_bool (*merge_checker_func_t)(HashTable *target_ht, void *source_data, zend_hash_key *hash_key, void *pParam);
471947b @zsuraski Reimplement PPP properties
zsuraski authored Feb 4, 2003
87
a32c54b Introduced a way to traverse hashes through external pointers.
Andrei Zmievski authored Mar 13, 2000
88 typedef Bucket* HashPosition;
89
fd4650b @zsuraski Add zend_hash_get_current_key_type()
zsuraski authored Jun 7, 1999
90 BEGIN_EXTERN_C()
91
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
92 /* startup/shutdown */
91b0d03 @zsuraski Add tracking for hashtable allocation
zsuraski authored Sep 17, 2002
93 ZEND_API int _zend_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC);
94 ZEND_API int _zend_hash_init_ex(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, zend_bool persistent, zend_bool bApplyProtection ZEND_FILE_LINE_DC);
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
95 ZEND_API void zend_hash_destroy(HashTable *ht);
96 ZEND_API void zend_hash_clean(HashTable *ht);
91b0d03 @zsuraski Add tracking for hashtable allocation
zsuraski authored Sep 17, 2002
97 #define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent) _zend_hash_init((ht), (nSize), (pHashFunction), (pDestructor), (persistent) ZEND_FILE_LINE_CC)
98 #define zend_hash_init_ex(ht, nSize, pHashFunction, pDestructor, persistent, bApplyProtection) _zend_hash_init_ex((ht), (nSize), (pHashFunction), (pDestructor), (persistent), (bApplyProtection) ZEND_FILE_LINE_CC)
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
99
100 /* additions/updates/changes */
4f6c95d @zsuraski Whitespace
zsuraski authored Aug 11, 2001
101 ZEND_API int zend_hash_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest, int flag);
102 #define zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest) \
103 zend_hash_add_or_update(ht, arKey, nKeyLength, pData, nDataSize, pDest, HASH_UPDATE)
104 #define zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest) \
105 zend_hash_add_or_update(ht, arKey, nKeyLength, pData, nDataSize, pDest, HASH_ADD)
106
107 ZEND_API int zend_hash_quick_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, ulong h, void *pData, uint nDataSize, void **pDest, int flag);
108 #define zend_hash_quick_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest) \
109 zend_hash_quick_add_or_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest, HASH_UPDATE)
110 #define zend_hash_quick_add(ht, arKey, nKeyLength, h, pData, nDataSize, pDest) \
111 zend_hash_quick_add_or_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest, HASH_ADD)
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
112
113 ZEND_API int zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag);
4f6c95d @zsuraski Whitespace
zsuraski authored Aug 11, 2001
114 #define zend_hash_index_update(ht, h, pData, nDataSize, pDest) \
115 zend_hash_index_update_or_next_insert(ht, h, pData, nDataSize, pDest, HASH_UPDATE)
116 #define zend_hash_next_index_insert(ht, pData, nDataSize, pDest) \
117 zend_hash_index_update_or_next_insert(ht, 0, pData, nDataSize, pDest, HASH_NEXT_INSERT)
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
118
755207a @zsuraski Implement zend_hash_add_empty_element() using the existing infrastruc…
zsuraski authored May 16, 2001
119 ZEND_API int zend_hash_add_empty_element(HashTable *ht, char *arKey, uint nKeyLength);
120
c14baee @zsuraski Avoid going over huge lists of functions, classes and constants.
zsuraski authored Aug 2, 2001
121
122 #define ZEND_HASH_APPLY_KEEP 0
123 #define ZEND_HASH_APPLY_REMOVE 1<<0
124 #define ZEND_HASH_APPLY_STOP 1<<1
125
746ce67 @andigutmans - Add hash_apply_with_arguments()
andigutmans authored Aug 25, 1999
126
7deb44e @zsuraski Some cleanup
zsuraski authored Aug 2, 2001
127 typedef int (*apply_func_t)(void *pDest TSRMLS_DC);
128 typedef int (*apply_func_arg_t)(void *pDest, void *argument TSRMLS_DC);
b51aa1f Made an alias for hash apply with arguments.
Andrei Zmievski authored Jun 9, 2000
129 typedef int (*apply_func_args_t)(void *pDest, int num_args, va_list args, zend_hash_key *hash_key);
130
ee08b81 @zsuraski - Make zend_hash_apply() (and friends) reentrant and much, much quicker
zsuraski authored Jan 16, 2000
131 ZEND_API void zend_hash_graceful_destroy(HashTable *ht);
bf5bb84 @sebastianbergmann MFZE1: make sure the resource-list is always consistent during shutdo…
sebastianbergmann authored Apr 19, 2002
132 ZEND_API void zend_hash_graceful_reverse_destroy(HashTable *ht);
d76cf1d @zsuraski More TSRMLS_FETCH work
zsuraski authored Jul 31, 2001
133 ZEND_API void zend_hash_apply(HashTable *ht, apply_func_t apply_func TSRMLS_DC);
134 ZEND_API void zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void * TSRMLS_DC);
1c2893a @zsuraski Minor cleaning
zsuraski authored Jul 15, 2001
135 ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, apply_func_args_t apply_func, int, ...);
746ce67 @andigutmans - Add hash_apply_with_arguments()
andigutmans authored Aug 25, 1999
136
c14baee @zsuraski Avoid going over huge lists of functions, classes and constants.
zsuraski authored Aug 2, 2001
137 /* This function should be used with special care (in other words,
138 * it should usually not be used). When used with the ZEND_HASH_APPLY_STOP
139 * return value, it assumes things about the order of the elements in the hash.
140 * Also, it does not provide the same kind of reentrancy protection that
141 * the standard apply functions do.
142 */
143 ZEND_API void zend_hash_reverse_apply(HashTable *ht, apply_func_t apply_func TSRMLS_DC);
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
144
145
146 /* Deletes */
147 ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag);
4f6c95d @zsuraski Whitespace
zsuraski authored Aug 11, 2001
148 #define zend_hash_del(ht, arKey, nKeyLength) \
149 zend_hash_del_key_or_index(ht, arKey, nKeyLength, 0, HASH_DEL_KEY)
150 #define zend_hash_index_del(ht, h) \
151 zend_hash_del_key_or_index(ht, NULL, 0, h, HASH_DEL_INDEX)
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
152
471947b @zsuraski Reimplement PPP properties
zsuraski authored Feb 4, 2003
153 ZEND_API ulong zend_get_hash_value(char *arKey, uint nKeyLength);
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
154
155 /* Data retreival */
156 ZEND_API int zend_hash_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData);
157 ZEND_API int zend_hash_quick_find(HashTable *ht, char *arKey, uint nKeyLength, ulong h, void **pData);
158 ZEND_API int zend_hash_index_find(HashTable *ht, ulong h, void **pData);
159
160 /* Misc */
161 ZEND_API int zend_hash_exists(HashTable *ht, char *arKey, uint nKeyLength);
376d631 @zsuraski Add quick_exists()
zsuraski authored Feb 5, 2003
162 ZEND_API int zend_hash_quick_exists(HashTable *ht, char *arKey, uint nKeyLength, ulong h);
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
163 ZEND_API int zend_hash_index_exists(HashTable *ht, ulong h);
164 ZEND_API ulong zend_hash_next_free_element(HashTable *ht);
165
cf90932 @zsuraski Improve infrastructure of numeric handling of elements in symbol tables.
zsuraski authored Jul 22, 2003
166
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
167 /* traversing */
184118d Make it a macro
Marcus Boerger authored Jul 20, 2003
168 #define zend_hash_has_more_elements_ex(ht, pos) \
169 (zend_hash_get_current_key_type_ex(ht, pos) == HASH_KEY_NON_EXISTANT ? FAILURE : SUCCESS)
ee286fe Make zend_hash_move_forward()/zenv_hash_move_backwards() a little sma…
Andrei Zmievski authored Mar 15, 2000
170 ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
171 ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
9b3df86 @zsuraski MFZE1
zsuraski authored Aug 20, 2001
172 ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, uint *str_length, ulong *num_index, zend_bool duplicate, HashPosition *pos);
a32c54b Introduced a way to traverse hashes through external pointers.
Andrei Zmievski authored Mar 13, 2000
173 ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
174 ZEND_API int zend_hash_get_current_data_ex(HashTable *ht, void **pData, HashPosition *pos);
175 ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
176 ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
177
892c1fb Add missing function to ease implementations
Marcus Boerger authored Jul 19, 2003
178 #define zend_hash_has_more_elements(ht) \
179 zend_hash_has_more_elements_ex(ht, NULL)
a32c54b Introduced a way to traverse hashes through external pointers.
Andrei Zmievski authored Mar 13, 2000
180 #define zend_hash_move_forward(ht) \
181 zend_hash_move_forward_ex(ht, NULL)
182 #define zend_hash_move_backwards(ht) \
183 zend_hash_move_backwards_ex(ht, NULL)
36eaad2 @zsuraski Allow get_current_key() not to return the key itself, instead of a du…
zsuraski authored Dec 22, 2000
184 #define zend_hash_get_current_key(ht, str_index, num_index, duplicate) \
185 zend_hash_get_current_key_ex(ht, str_index, NULL, num_index, duplicate, NULL)
a32c54b Introduced a way to traverse hashes through external pointers.
Andrei Zmievski authored Mar 13, 2000
186 #define zend_hash_get_current_key_type(ht) \
187 zend_hash_get_current_key_type_ex(ht, NULL)
188 #define zend_hash_get_current_data(ht, pData) \
189 zend_hash_get_current_data_ex(ht, pData, NULL)
190 #define zend_hash_internal_pointer_reset(ht) \
191 zend_hash_internal_pointer_reset_ex(ht, NULL)
192 #define zend_hash_internal_pointer_end(ht) \
193 zend_hash_internal_pointer_end_ex(ht, NULL)
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
194
195 /* Copying, merging and sorting */
9f51f15 @zsuraski - Stop passing list/plist to internal functions
zsuraski authored Feb 5, 2000
196 ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size);
197 ZEND_API void zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite);
471947b @zsuraski Reimplement PPP properties
zsuraski authored Feb 4, 2003
198 ZEND_API void zend_hash_merge_ex(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, uint size, merge_checker_func_t pMergeSource, void *pParam);
3bdddb4 @sebastianbergmann MFZE1
sebastianbergmann authored Sep 19, 2001
199 ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber TSRMLS_DC);
8ce8324 @zsuraski More TSRMLS_FETCH annihilation
zsuraski authored Jul 30, 2001
200 ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, zend_bool ordered TSRMLS_DC);
3bdddb4 @sebastianbergmann MFZE1
sebastianbergmann authored Sep 19, 2001
201 ZEND_API int zend_hash_minmax(HashTable *ht, compare_func_t compar, int flag, void **pData TSRMLS_DC);
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
202
203 ZEND_API int zend_hash_num_elements(HashTable *ht);
204
3964c92 Made zend_hash_rehash() callable from outside.
Andrei Zmievski authored Nov 4, 1999
205 ZEND_API int zend_hash_rehash(HashTable *ht);
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
206
1186d51 @andigutmans - Add a loop unrolled version of the hash function and a bit of an
andigutmans authored Jun 8, 2002
207 /*
208 * DJBX33A (Daniel J. Bernstein, Times 33 with Addition)
209 *
210 * This is Daniel J. Bernstein's popular `times 33' hash function as
211 * posted by him years ago on comp.lang.c. It basically uses a function
212 * like ``hash(i) = hash(i-1) * 33 + str[i]''. This is one of the best
213 * known hash functions for strings. Because it is both computed very
214 * fast and distributes very well.
215 *
216 * The magic of number 33, i.e. why it works better than many other
217 * constants, prime or not, has never been adequately explained by
218 * anyone. So I try an explanation: if one experimentally tests all
219 * multipliers between 1 and 256 (as RSE did now) one detects that even
220 * numbers are not useable at all. The remaining 128 odd numbers
221 * (except for the number 1) work more or less all equally well. They
222 * all distribute in an acceptable way and this way fill a hash table
223 * with an average percent of approx. 86%.
224 *
225 * If one compares the Chi^2 values of the variants, the number 33 not
226 * even has the best value. But the number 33 and a few other equally
227 * good numbers like 17, 31, 63, 127 and 129 have nevertheless a great
228 * advantage to the remaining numbers in the large set of possible
229 * multipliers: their multiply operation can be replaced by a faster
230 * operation based on just one shift plus either a single addition
231 * or subtraction operation. And because a hash function has to both
232 * distribute good _and_ has to be very fast to compute, those few
233 * numbers should be preferred and seems to be the reason why Daniel J.
234 * Bernstein also preferred it.
235 *
236 *
237 * -- Ralf S. Engelschall <rse@engelschall.com>
238 */
239
b98acd6 @andigutmans - Move inline_zend_hash_func() to header file
andigutmans authored Jul 11, 2001
240 static inline ulong zend_inline_hash_func(char *arKey, uint nKeyLength)
241 {
1186d51 @andigutmans - Add a loop unrolled version of the hash function and a bit of an
andigutmans authored Jun 8, 2002
242 register ulong hash = 5381;
243
244 /* variant with the hash unrolled eight times */
245 for (; nKeyLength >= 8; nKeyLength -= 8) {
246 hash = ((hash << 5) + hash) + *arKey++;
247 hash = ((hash << 5) + hash) + *arKey++;
248 hash = ((hash << 5) + hash) + *arKey++;
249 hash = ((hash << 5) + hash) + *arKey++;
250 hash = ((hash << 5) + hash) + *arKey++;
251 hash = ((hash << 5) + hash) + *arKey++;
252 hash = ((hash << 5) + hash) + *arKey++;
253 hash = ((hash << 5) + hash) + *arKey++;
254 }
255 switch (nKeyLength) {
256 case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
257 case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
258 case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
259 case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
260 case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
261 case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
262 case 1: hash = ((hash << 5) + hash) + *arKey++; break;
90f43c7 @andigutmans - This should improve performance on Windows
andigutmans authored Jun 8, 2002
263 case 0: break;
264 EMPTY_SWITCH_DEFAULT_CASE()
b98acd6 @andigutmans - Move inline_zend_hash_func() to header file
andigutmans authored Jul 11, 2001
265 }
1186d51 @andigutmans - Add a loop unrolled version of the hash function and a bit of an
andigutmans authored Jun 8, 2002
266 return hash;
b98acd6 @andigutmans - Move inline_zend_hash_func() to header file
andigutmans authored Jul 11, 2001
267 }
268
1186d51 @andigutmans - Add a loop unrolled version of the hash function and a bit of an
andigutmans authored Jun 8, 2002
269
6cf5e7f @smalyshev No hashpjw anymore, but we have zend_hash_func
smalyshev authored Jul 11, 2001
270 ZEND_API ulong zend_hash_func(char *arKey, uint nKeyLength);
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
271
9353650 Fix warnings surfacing in maintainer-mode.
Stig S. Bakken authored Dec 1, 1999
272 #if ZEND_DEBUG
573b460 @andigutmans Zend Library
andigutmans authored Apr 7, 1999
273 /* debug */
274 void zend_hash_display_pListTail(HashTable *ht);
275 void zend_hash_display(HashTable *ht);
276 #endif
277
fd4650b @zsuraski Add zend_hash_get_current_key_type()
zsuraski authored Jun 7, 1999
278 END_EXTERN_C()
279
0a14a32 @zsuraski Add useful macros
zsuraski authored Apr 25, 2000
280 #define ZEND_INIT_SYMTABLE(ht) \
281 ZEND_INIT_SYMTABLE_EX(ht, 2, 0)
282
283 #define ZEND_INIT_SYMTABLE_EX(ht, n, persistent) \
284 zend_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
285
286
e89977f @zsuraski Go back to ZE1-like code
zsuraski authored Jul 23, 2003
287 #define HANDLE_NUMERIC(key, length, func) { \
288 register char *tmp=key; \
289 \
290 if ((*tmp>='0' && *tmp<='9')) do { /* possibly a numeric index */ \
291 char *end=tmp+length-1; \
292 ulong idx; \
293 \
294 if (*tmp++=='0' && length>2) { /* don't accept numbers with leading zeros */ \
295 break; \
296 } \
297 while (tmp<end) { \
298 if (!(*tmp>='0' && *tmp<='9')) { \
299 break; \
300 } \
301 tmp++; \
302 } \
303 if (tmp==end && *tmp=='\0') { /* a numeric index */ \
304 idx = strtol(key, NULL, 10); \
305 if (idx!=LONG_MAX) { \
306 return func; \
307 } \
308 } \
309 } while (0); \
310 }
311
312
cf90932 @zsuraski Improve infrastructure of numeric handling of elements in symbol tables.
zsuraski authored Jul 22, 2003
313 static inline int zend_symtable_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest) \
314 {
e89977f @zsuraski Go back to ZE1-like code
zsuraski authored Jul 23, 2003
315 HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_update(ht, idx, pData, nDataSize, pDest));
316 return zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest);
cf90932 @zsuraski Improve infrastructure of numeric handling of elements in symbol tables.
zsuraski authored Jul 22, 2003
317 }
318
319
320 static inline int zend_symtable_del(HashTable *ht, char *arKey, uint nKeyLength)
321 {
e89977f @zsuraski Go back to ZE1-like code
zsuraski authored Jul 23, 2003
322 HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_del(ht, idx))
323 return zend_hash_del(ht, arKey, nKeyLength);
cf90932 @zsuraski Improve infrastructure of numeric handling of elements in symbol tables.
zsuraski authored Jul 22, 2003
324 }
325
326
327 static inline int zend_symtable_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData)
328 {
e89977f @zsuraski Go back to ZE1-like code
zsuraski authored Jul 23, 2003
329 HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_find(ht, idx, pData));
330 return zend_hash_find(ht, arKey, nKeyLength, pData);
cf90932 @zsuraski Improve infrastructure of numeric handling of elements in symbol tables.
zsuraski authored Jul 22, 2003
331 }
332
333
334 static inline int zend_symtable_exists(HashTable *ht, char *arKey, uint nKeyLength)
335 {
e89977f @zsuraski Go back to ZE1-like code
zsuraski authored Jul 23, 2003
336 HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_exists(ht, idx));
337 return zend_hash_exists(ht, arKey, nKeyLength);
cf90932 @zsuraski Improve infrastructure of numeric handling of elements in symbol tables.
zsuraski authored Jul 22, 2003
338 }
339
a617217 Replace macros which begin with an underscore through an appropiately
Sascha Schumann authored Jul 3, 2000
340 #endif /* ZEND_HASH_H */
333406b - Added some missing CVS $Id$ tags, headers and footers.
foobar authored Feb 1, 2003
341
342 /*
343 * Local variables:
344 * tab-width: 4
345 * c-basic-offset: 4
346 * indent-tabs-mode: t
347 * End:
348 */
Something went wrong with that request. Please try again.