Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 393 lines (329 sloc) 17.507 kb
573b4602 »
1999-04-07 Zend Library
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
8775a375 »
2012-01-01 - Year++
5 | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
573b4602 »
1999-04-07 Zend Library
6 +----------------------------------------------------------------------+
d863d52a »
2001-12-11 Update headers.
7 | This source file is subject to version 2.00 of the Zend license, |
b5b11177 »
1999-07-16 License update
8 | that is bundled with this package in the file LICENSE, and is |
f68c7ff2 »
2003-06-10 updating license information in the headers.
9 | available through the world-wide-web at the following url: |
d863d52a »
2001-12-11 Update headers.
10 | http://www.zend.com/license/2_00.txt. |
b5b11177 »
1999-07-16 License update
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. |
573b4602 »
1999-04-07 Zend Library
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 +----------------------------------------------------------------------+
18 */
19
333406bd »
2003-02-01 - Added some missing CVS $Id$ tags, headers and footers.
20 /* $Id$ */
21
a6172174 »
2000-07-03 Replace macros which begin with an underscore through an appropiately
22 #ifndef ZEND_HASH_H
23 #define ZEND_HASH_H
573b4602 »
1999-04-07 Zend Library
24
25 #include <sys/types.h>
90f43c78 »
2002-06-08 - This should improve performance on Windows
26 #include "zend.h"
573b4602 »
1999-04-07 Zend Library
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
2ecf4bb0 »
2008-04-29 Lazy EG(active_symbol_table) initialization
38 #define HASH_DEL_KEY_QUICK 2
573b4602 »
1999-04-07 Zend Library
39
37a76935 »
2008-08-01 Fixed bug #44100 (Inconsistent handling of static array declarations …
40 #define HASH_UPDATE_KEY_IF_NONE 0
41 #define HASH_UPDATE_KEY_IF_BEFORE 1
42 #define HASH_UPDATE_KEY_IF_AFTER 2
43 #define HASH_UPDATE_KEY_ANYWAY 3
44
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
45 typedef ulong (*hash_func_t)(const char *arKey, uint nKeyLength);
3bdddb49 »
2001-09-19 MFZE1
46 typedef int (*compare_func_t)(const void *, const void * TSRMLS_DC);
47 typedef void (*sort_func_t)(void *, size_t, register size_t, compare_func_t TSRMLS_DC);
62114c18 »
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
48 typedef void (*dtor_func_t)(void *pDest);
9f51f154 »
2000-02-05 - Stop passing list/plist to internal functions
49 typedef void (*copy_ctor_func_t)(void *pElement);
e062dffe »
2002-12-06 - Implement public/protected/private methods.
50 typedef void (*copy_ctor_param_func_t)(void *pElement, void *pParam);
62114c18 »
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
51
9b916e6a »
2000-05-24 rename hastable -> _hashtable to avoid clashes
52 struct _hashtable;
573b4602 »
1999-04-07 Zend Library
53
54 typedef struct bucket {
55 ulong h; /* Used for numeric indexing */
56 uint nKeyLength;
57 void *pData;
58 void *pDataPtr;
59 struct bucket *pListNext;
60 struct bucket *pListLast;
61 struct bucket *pNext;
aa73f6b6 »
2000-01-19 - Hopefully fix the hash problem.
62 struct bucket *pLast;
e43ff135 »
2011-09-13 Fixed ZE specific compile warnings (Bug #55629)
63 const char *arKey;
573b4602 »
1999-04-07 Zend Library
64 } Bucket;
65
9b916e6a »
2000-05-24 rename hastable -> _hashtable to avoid clashes
66 typedef struct _hashtable {
573b4602 »
1999-04-07 Zend Library
67 uint nTableSize;
2f8fa8cf »
2001-07-10 - Merge faster hash implementation.
68 uint nTableMask;
573b4602 »
1999-04-07 Zend Library
69 uint nNumOfElements;
70 ulong nNextFreeElement;
71 Bucket *pInternalPointer; /* Used for element traversal */
72 Bucket *pListHead;
73 Bucket *pListTail;
74 Bucket **arBuckets;
62114c18 »
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
75 dtor_func_t pDestructor;
38cdb8e7 »
2000-06-17 Avoid crashing with recursive applies - limit apply nest level to 3 (…
76 zend_bool persistent;
77 unsigned char nApplyCount;
1263932a »
2000-07-11 Disable the hash_apply() protection on hashes that persist across req…
78 zend_bool bApplyProtection;
c93a1890 »
2000-01-15 if ZEND_DEBUG mode is on we'll now see warnings when a HashTable is a…
79 #if ZEND_DEBUG
80 int inconsistent;
81 #endif
573b4602 »
1999-04-07 Zend Library
82 } HashTable;
83
471947b1 »
2003-02-04 Reimplement PPP properties
84
85 typedef struct _zend_hash_key {
e43ff135 »
2011-09-13 Fixed ZE specific compile warnings (Bug #55629)
86 const char *arKey;
471947b1 »
2003-02-04 Reimplement PPP properties
87 uint nKeyLength;
88 ulong h;
89 } zend_hash_key;
90
91
45c12359 »
2003-02-06 Fix prototype (may have caused stack corruption)
92 typedef zend_bool (*merge_checker_func_t)(HashTable *target_ht, void *source_data, zend_hash_key *hash_key, void *pParam);
471947b1 »
2003-02-04 Reimplement PPP properties
93
a32c54bd »
2000-03-13 Introduced a way to traverse hashes through external pointers.
94 typedef Bucket* HashPosition;
95
fd4650b5 »
1999-06-07 Add zend_hash_get_current_key_type()
96 BEGIN_EXTERN_C()
97
573b4602 »
1999-04-07 Zend Library
98 /* startup/shutdown */
91b0d033 »
2002-09-17 Add tracking for hashtable allocation
99 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);
100 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);
573b4602 »
1999-04-07 Zend Library
101 ZEND_API void zend_hash_destroy(HashTable *ht);
102 ZEND_API void zend_hash_clean(HashTable *ht);
91b0d033 »
2002-09-17 Add tracking for hashtable allocation
103 #define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent) _zend_hash_init((ht), (nSize), (pHashFunction), (pDestructor), (persistent) ZEND_FILE_LINE_CC)
104 #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)
573b4602 »
1999-04-07 Zend Library
105
106 /* additions/updates/changes */
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
107 ZEND_API int _zend_hash_add_or_update(HashTable *ht, const char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest, int flag ZEND_FILE_LINE_DC);
4f6c95d1 »
2001-08-11 Whitespace
108 #define zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest) \
0dba58c3 »
2003-08-18 Improve tracking
109 _zend_hash_add_or_update(ht, arKey, nKeyLength, pData, nDataSize, pDest, HASH_UPDATE ZEND_FILE_LINE_CC)
4f6c95d1 »
2001-08-11 Whitespace
110 #define zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest) \
0dba58c3 »
2003-08-18 Improve tracking
111 _zend_hash_add_or_update(ht, arKey, nKeyLength, pData, nDataSize, pDest, HASH_ADD ZEND_FILE_LINE_CC)
4f6c95d1 »
2001-08-11 Whitespace
112
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
113 ZEND_API int _zend_hash_quick_add_or_update(HashTable *ht, const char *arKey, uint nKeyLength, ulong h, void *pData, uint nDataSize, void **pDest, int flag ZEND_FILE_LINE_DC);
4f6c95d1 »
2001-08-11 Whitespace
114 #define zend_hash_quick_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest) \
0dba58c3 »
2003-08-18 Improve tracking
115 _zend_hash_quick_add_or_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest, HASH_UPDATE ZEND_FILE_LINE_CC)
4f6c95d1 »
2001-08-11 Whitespace
116 #define zend_hash_quick_add(ht, arKey, nKeyLength, h, pData, nDataSize, pDest) \
0dba58c3 »
2003-08-18 Improve tracking
117 _zend_hash_quick_add_or_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest, HASH_ADD ZEND_FILE_LINE_CC)
573b4602 »
1999-04-07 Zend Library
118
0dba58c3 »
2003-08-18 Improve tracking
119 ZEND_API int _zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag ZEND_FILE_LINE_DC);
4f6c95d1 »
2001-08-11 Whitespace
120 #define zend_hash_index_update(ht, h, pData, nDataSize, pDest) \
0dba58c3 »
2003-08-18 Improve tracking
121 _zend_hash_index_update_or_next_insert(ht, h, pData, nDataSize, pDest, HASH_UPDATE ZEND_FILE_LINE_CC)
4f6c95d1 »
2001-08-11 Whitespace
122 #define zend_hash_next_index_insert(ht, pData, nDataSize, pDest) \
0dba58c3 »
2003-08-18 Improve tracking
123 _zend_hash_index_update_or_next_insert(ht, 0, pData, nDataSize, pDest, HASH_NEXT_INSERT ZEND_FILE_LINE_CC)
573b4602 »
1999-04-07 Zend Library
124
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
125 ZEND_API int zend_hash_add_empty_element(HashTable *ht, const char *arKey, uint nKeyLength);
755207a1 »
2001-05-16 Implement zend_hash_add_empty_element() using the existing infrastruc…
126
c14baeec »
2001-08-02 Avoid going over huge lists of functions, classes and constants.
127
128 #define ZEND_HASH_APPLY_KEEP 0
129 #define ZEND_HASH_APPLY_REMOVE 1<<0
130 #define ZEND_HASH_APPLY_STOP 1<<1
131
7deb44e3 »
2001-08-02 Some cleanup
132 typedef int (*apply_func_t)(void *pDest TSRMLS_DC);
133 typedef int (*apply_func_arg_t)(void *pDest, void *argument TSRMLS_DC);
0fbe6a0c »
2008-07-24 - MFH: Added TSRMLS_DC to apply_func_args_t and zend_hash_apply_with_…
134 typedef int (*apply_func_args_t)(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
b51aa1f3 »
2000-06-09 Made an alias for hash apply with arguments.
135
ee08b81a »
2000-01-16 - Make zend_hash_apply() (and friends) reentrant and much, much quicker
136 ZEND_API void zend_hash_graceful_destroy(HashTable *ht);
bf5bb842 »
2002-04-19 MFZE1: make sure the resource-list is always consistent during shutdo…
137 ZEND_API void zend_hash_graceful_reverse_destroy(HashTable *ht);
d76cf1da »
2001-07-31 More TSRMLS_FETCH work
138 ZEND_API void zend_hash_apply(HashTable *ht, apply_func_t apply_func TSRMLS_DC);
139 ZEND_API void zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void * TSRMLS_DC);
0fbe6a0c »
2008-07-24 - MFH: Added TSRMLS_DC to apply_func_args_t and zend_hash_apply_with_…
140 ZEND_API void zend_hash_apply_with_arguments(HashTable *ht TSRMLS_DC, apply_func_args_t apply_func, int, ...);
746ce67b »
1999-08-25 - Add hash_apply_with_arguments()
141
c14baeec »
2001-08-02 Avoid going over huge lists of functions, classes and constants.
142 /* This function should be used with special care (in other words,
143 * it should usually not be used). When used with the ZEND_HASH_APPLY_STOP
144 * return value, it assumes things about the order of the elements in the hash.
145 * Also, it does not provide the same kind of reentrancy protection that
146 * the standard apply functions do.
147 */
148 ZEND_API void zend_hash_reverse_apply(HashTable *ht, apply_func_t apply_func TSRMLS_DC);
573b4602 »
1999-04-07 Zend Library
149
150
151 /* Deletes */
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
152 ZEND_API int zend_hash_del_key_or_index(HashTable *ht, const char *arKey, uint nKeyLength, ulong h, int flag);
4f6c95d1 »
2001-08-11 Whitespace
153 #define zend_hash_del(ht, arKey, nKeyLength) \
154 zend_hash_del_key_or_index(ht, arKey, nKeyLength, 0, HASH_DEL_KEY)
2ecf4bb0 »
2008-04-29 Lazy EG(active_symbol_table) initialization
155 #define zend_hash_quick_del(ht, arKey, nKeyLength, h) \
156 zend_hash_del_key_or_index(ht, arKey, nKeyLength, h, HASH_DEL_KEY_QUICK)
4f6c95d1 »
2001-08-11 Whitespace
157 #define zend_hash_index_del(ht, h) \
158 zend_hash_del_key_or_index(ht, NULL, 0, h, HASH_DEL_INDEX)
573b4602 »
1999-04-07 Zend Library
159
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
160 ZEND_API ulong zend_get_hash_value(const char *arKey, uint nKeyLength);
573b4602 »
1999-04-07 Zend Library
161
162 /* Data retreival */
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
163 ZEND_API int zend_hash_find(const HashTable *ht, const char *arKey, uint nKeyLength, void **pData);
164 ZEND_API int zend_hash_quick_find(const HashTable *ht, const char *arKey, uint nKeyLength, ulong h, void **pData);
165 ZEND_API int zend_hash_index_find(const HashTable *ht, ulong h, void **pData);
573b4602 »
1999-04-07 Zend Library
166
167 /* Misc */
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
168 ZEND_API int zend_hash_exists(const HashTable *ht, const char *arKey, uint nKeyLength);
169 ZEND_API int zend_hash_quick_exists(const HashTable *ht, const char *arKey, uint nKeyLength, ulong h);
170 ZEND_API int zend_hash_index_exists(const HashTable *ht, ulong h);
171 ZEND_API ulong zend_hash_next_free_element(const HashTable *ht);
573b4602 »
1999-04-07 Zend Library
172
cf90932a »
2003-07-22 Improve infrastructure of numeric handling of elements in symbol tables.
173
573b4602 »
1999-04-07 Zend Library
174 /* traversing */
184118d9 »
2003-07-20 Make it a macro
175 #define zend_hash_has_more_elements_ex(ht, pos) \
176 (zend_hash_get_current_key_type_ex(ht, pos) == HASH_KEY_NON_EXISTANT ? FAILURE : SUCCESS)
ee286feb »
2000-03-15 Make zend_hash_move_forward()/zenv_hash_move_backwards() a little sma…
177 ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
178 ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
179 ZEND_API int zend_hash_get_current_key_ex(const HashTable *ht, char **str_index, uint *str_length, ulong *num_index, zend_bool duplicate, HashPosition *pos);
a32c54bd »
2000-03-13 Introduced a way to traverse hashes through external pointers.
180 ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
181 ZEND_API int zend_hash_get_current_data_ex(HashTable *ht, void **pData, HashPosition *pos);
182 ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
183 ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
37a76935 »
2008-08-01 Fixed bug #44100 (Inconsistent handling of static array declarations …
184 ZEND_API int zend_hash_update_current_key_ex(HashTable *ht, int key_type, const char *str_index, uint str_length, ulong num_index, int mode, HashPosition *pos);
a32c54bd »
2000-03-13 Introduced a way to traverse hashes through external pointers.
185
e470e22e »
2007-01-10 - Fixed bug #35106 (nested foreach fails when array variable has a re…
186 typedef struct _HashPointer {
187 HashPosition pos;
188 ulong h;
189 } HashPointer;
190
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
191 ZEND_API int zend_hash_get_pointer(const HashTable *ht, HashPointer *ptr);
e470e22e »
2007-01-10 - Fixed bug #35106 (nested foreach fails when array variable has a re…
192 ZEND_API int zend_hash_set_pointer(HashTable *ht, const HashPointer *ptr);
193
892c1fbb »
2003-07-19 Add missing function to ease implementations
194 #define zend_hash_has_more_elements(ht) \
195 zend_hash_has_more_elements_ex(ht, NULL)
a32c54bd »
2000-03-13 Introduced a way to traverse hashes through external pointers.
196 #define zend_hash_move_forward(ht) \
197 zend_hash_move_forward_ex(ht, NULL)
198 #define zend_hash_move_backwards(ht) \
199 zend_hash_move_backwards_ex(ht, NULL)
36eaad25 »
2000-12-22 Allow get_current_key() not to return the key itself, instead of a du…
200 #define zend_hash_get_current_key(ht, str_index, num_index, duplicate) \
201 zend_hash_get_current_key_ex(ht, str_index, NULL, num_index, duplicate, NULL)
a32c54bd »
2000-03-13 Introduced a way to traverse hashes through external pointers.
202 #define zend_hash_get_current_key_type(ht) \
203 zend_hash_get_current_key_type_ex(ht, NULL)
204 #define zend_hash_get_current_data(ht, pData) \
205 zend_hash_get_current_data_ex(ht, pData, NULL)
206 #define zend_hash_internal_pointer_reset(ht) \
207 zend_hash_internal_pointer_reset_ex(ht, NULL)
208 #define zend_hash_internal_pointer_end(ht) \
209 zend_hash_internal_pointer_end_ex(ht, NULL)
d9c1a380 »
2005-07-07 Fixed bug #28072 (static array with some constant keys will be incorr…
210 #define zend_hash_update_current_key(ht, key_type, str_index, str_length, num_index) \
37a76935 »
2008-08-01 Fixed bug #44100 (Inconsistent handling of static array declarations …
211 zend_hash_update_current_key_ex(ht, key_type, str_index, str_length, num_index, HASH_UPDATE_KEY_ANYWAY, NULL)
573b4602 »
1999-04-07 Zend Library
212
213 /* Copying, merging and sorting */
9f51f154 »
2000-02-05 - Stop passing list/plist to internal functions
214 ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size);
0dba58c3 »
2003-08-18 Improve tracking
215 ZEND_API void _zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite ZEND_FILE_LINE_DC);
471947b1 »
2003-02-04 Reimplement PPP properties
216 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);
3bdddb49 »
2001-09-19 MFZE1
217 ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber TSRMLS_DC);
8ce8324e »
2001-07-30 More TSRMLS_FETCH annihilation
218 ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, zend_bool ordered TSRMLS_DC);
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
219 ZEND_API int zend_hash_minmax(const HashTable *ht, compare_func_t compar, int flag, void **pData TSRMLS_DC);
573b4602 »
1999-04-07 Zend Library
220
0dba58c3 »
2003-08-18 Improve tracking
221 #define zend_hash_merge(target, source, pCopyConstructor, tmp, size, overwrite) \
222 _zend_hash_merge(target, source, pCopyConstructor, tmp, size, overwrite ZEND_FILE_LINE_CC)
223
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
224 ZEND_API int zend_hash_num_elements(const HashTable *ht);
573b4602 »
1999-04-07 Zend Library
225
3964c92f »
1999-11-04 Made zend_hash_rehash() callable from outside.
226 ZEND_API int zend_hash_rehash(HashTable *ht);
573b4602 »
1999-04-07 Zend Library
227
1186d51c »
2002-06-08 - Add a loop unrolled version of the hash function and a bit of an
228 /*
229 * DJBX33A (Daniel J. Bernstein, Times 33 with Addition)
230 *
231 * This is Daniel J. Bernstein's popular `times 33' hash function as
232 * posted by him years ago on comp.lang.c. It basically uses a function
233 * like ``hash(i) = hash(i-1) * 33 + str[i]''. This is one of the best
234 * known hash functions for strings. Because it is both computed very
235 * fast and distributes very well.
236 *
237 * The magic of number 33, i.e. why it works better than many other
238 * constants, prime or not, has never been adequately explained by
239 * anyone. So I try an explanation: if one experimentally tests all
240 * multipliers between 1 and 256 (as RSE did now) one detects that even
241 * numbers are not useable at all. The remaining 128 odd numbers
242 * (except for the number 1) work more or less all equally well. They
243 * all distribute in an acceptable way and this way fill a hash table
244 * with an average percent of approx. 86%.
245 *
246 * If one compares the Chi^2 values of the variants, the number 33 not
247 * even has the best value. But the number 33 and a few other equally
248 * good numbers like 17, 31, 63, 127 and 129 have nevertheless a great
249 * advantage to the remaining numbers in the large set of possible
250 * multipliers: their multiply operation can be replaced by a faster
251 * operation based on just one shift plus either a single addition
252 * or subtraction operation. And because a hash function has to both
253 * distribute good _and_ has to be very fast to compute, those few
254 * numbers should be preferred and seems to be the reason why Daniel J.
255 * Bernstein also preferred it.
256 *
257 *
258 * -- Ralf S. Engelschall <rse@engelschall.com>
259 */
260
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
261 static inline ulong zend_inline_hash_func(const char *arKey, uint nKeyLength)
b98acd61 »
2001-07-11 - Move inline_zend_hash_func() to header file
262 {
1186d51c »
2002-06-08 - Add a loop unrolled version of the hash function and a bit of an
263 register ulong hash = 5381;
264
265 /* variant with the hash unrolled eight times */
266 for (; nKeyLength >= 8; nKeyLength -= 8) {
267 hash = ((hash << 5) + hash) + *arKey++;
268 hash = ((hash << 5) + hash) + *arKey++;
269 hash = ((hash << 5) + hash) + *arKey++;
270 hash = ((hash << 5) + hash) + *arKey++;
271 hash = ((hash << 5) + hash) + *arKey++;
272 hash = ((hash << 5) + hash) + *arKey++;
273 hash = ((hash << 5) + hash) + *arKey++;
274 hash = ((hash << 5) + hash) + *arKey++;
275 }
276 switch (nKeyLength) {
277 case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
278 case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
279 case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
280 case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
281 case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
282 case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
283 case 1: hash = ((hash << 5) + hash) + *arKey++; break;
90f43c78 »
2002-06-08 - This should improve performance on Windows
284 case 0: break;
285 EMPTY_SWITCH_DEFAULT_CASE()
b98acd61 »
2001-07-11 - Move inline_zend_hash_func() to header file
286 }
1186d51c »
2002-06-08 - Add a loop unrolled version of the hash function and a bit of an
287 return hash;
b98acd61 »
2001-07-11 - Move inline_zend_hash_func() to header file
288 }
289
1186d51c »
2002-06-08 - Add a loop unrolled version of the hash function and a bit of an
290
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
291 ZEND_API ulong zend_hash_func(const char *arKey, uint nKeyLength);
573b4602 »
1999-04-07 Zend Library
292
93536507 »
1999-12-01 Fix warnings surfacing in maintainer-mode.
293 #if ZEND_DEBUG
573b4602 »
1999-04-07 Zend Library
294 /* debug */
cf7384aa »
2008-08-12 - MFH: Constness (Added const qualifier to several function parameters)
295 void zend_hash_display_pListTail(const HashTable *ht);
296 void zend_hash_display(const HashTable *ht);
573b4602 »
1999-04-07 Zend Library
297 #endif
298
fd4650b5 »
1999-06-07 Add zend_hash_get_current_key_type()
299 END_EXTERN_C()
300
0a14a32c »
2000-04-25 Add useful macros
301 #define ZEND_INIT_SYMTABLE(ht) \
302 ZEND_INIT_SYMTABLE_EX(ht, 2, 0)
303
304 #define ZEND_INIT_SYMTABLE_EX(ht, n, persistent) \
305 zend_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
306
94dd8372 »
2010-04-20 Changed the structure of op_array.opcodes. The constant values are mo…
307 #define ZEND_HANDLE_NUMERIC_EX(key, length, idx, func) do { \
d3b42700 »
2009-03-18 Better fix for bug #45877 (smaller and faster)
308 register const char *tmp = key; \
309 \
310 if (*tmp == '-') { \
311 tmp++; \
312 } \
9f32cb2d »
2009-03-19 Fixed check for long integer overflow
313 if (*tmp >= '0' && *tmp <= '9') { /* possibly a numeric index */ \
314 const char *end = key + length - 1; \
315 \
4658d940 »
2009-03-24 Fixed "-0" parsing and optimized overflow check (Matt)
316 if ((*end != '\0') /* not a null terminated string */ \
317 || (*tmp == '0' && length > 2) /* numbers with leading zeros */ \
318 || (end - tmp > MAX_LENGTH_OF_LONG - 1) /* number too long */ \
319 || (SIZEOF_LONG == 4 && \
320 end - tmp == MAX_LENGTH_OF_LONG - 1 && \
321 *tmp > '2')) { /* overflow */ \
9f32cb2d »
2009-03-19 Fixed check for long integer overflow
322 break; \
4658d940 »
2009-03-24 Fixed "-0" parsing and optimized overflow check (Matt)
323 } \
324 idx = (*tmp - '0'); \
325 while (++tmp != end && *tmp >= '0' && *tmp <= '9') { \
326 idx = (idx * 10) + (*tmp - '0'); \
327 } \
328 if (tmp == end) { \
329 if (*key == '-') { \
fa3f0bb6 »
2010-10-05 Fixed bug #51008 (Zend/tests/bug45877.phpt fails)
330 if (idx-1 > LONG_MAX) { /* overflow */ \
d3b42700 »
2009-03-18 Better fix for bug #45877 (smaller and faster)
331 break; \
332 } \
e6d9cd98 »
2012-07-08 appease MSVC (doesnt like unary minus of unsigned ints)
333 idx = 0 - idx; \
fa3f0bb6 »
2010-10-05 Fixed bug #51008 (Zend/tests/bug45877.phpt fails)
334 } else if (idx > LONG_MAX) { /* overflow */ \
4658d940 »
2009-03-24 Fixed "-0" parsing and optimized overflow check (Matt)
335 break; \
d3b42700 »
2009-03-18 Better fix for bug #45877 (smaller and faster)
336 } \
94dd8372 »
2010-04-20 Changed the structure of op_array.opcodes. The constant values are mo…
337 func; \
d3b42700 »
2009-03-18 Better fix for bug #45877 (smaller and faster)
338 } \
339 } \
340 } while (0)
e89977f9 »
2003-07-23 Go back to ZE1-like code
341
94dd8372 »
2010-04-20 Changed the structure of op_array.opcodes. The constant values are mo…
342 #define ZEND_HANDLE_NUMERIC(key, length, func) do { \
fa3f0bb6 »
2010-10-05 Fixed bug #51008 (Zend/tests/bug45877.phpt fails)
343 ulong idx; \
94dd8372 »
2010-04-20 Changed the structure of op_array.opcodes. The constant values are mo…
344 \
345 ZEND_HANDLE_NUMERIC_EX(key, length, idx, return func); \
346 } while (0)
347
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
348 static inline int zend_symtable_update(HashTable *ht, const char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest) \
cf90932a »
2003-07-22 Improve infrastructure of numeric handling of elements in symbol tables.
349 {
b101ee1a »
2008-01-15 MFH: rename macros
350 ZEND_HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_update(ht, idx, pData, nDataSize, pDest));
e89977f9 »
2003-07-23 Go back to ZE1-like code
351 return zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest);
cf90932a »
2003-07-22 Improve infrastructure of numeric handling of elements in symbol tables.
352 }
353
354
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
355 static inline int zend_symtable_del(HashTable *ht, const char *arKey, uint nKeyLength)
cf90932a »
2003-07-22 Improve infrastructure of numeric handling of elements in symbol tables.
356 {
d3b42700 »
2009-03-18 Better fix for bug #45877 (smaller and faster)
357 ZEND_HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_del(ht, idx));
e89977f9 »
2003-07-23 Go back to ZE1-like code
358 return zend_hash_del(ht, arKey, nKeyLength);
cf90932a »
2003-07-22 Improve infrastructure of numeric handling of elements in symbol tables.
359 }
360
361
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
362 static inline int zend_symtable_find(HashTable *ht, const char *arKey, uint nKeyLength, void **pData)
cf90932a »
2003-07-22 Improve infrastructure of numeric handling of elements in symbol tables.
363 {
b101ee1a »
2008-01-15 MFH: rename macros
364 ZEND_HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_find(ht, idx, pData));
e89977f9 »
2003-07-23 Go back to ZE1-like code
365 return zend_hash_find(ht, arKey, nKeyLength, pData);
cf90932a »
2003-07-22 Improve infrastructure of numeric handling of elements in symbol tables.
366 }
367
368
6c810b0d »
2007-09-27 Improved memory usage by movig constants to read only memory. (Dmitry…
369 static inline int zend_symtable_exists(HashTable *ht, const char *arKey, uint nKeyLength)
cf90932a »
2003-07-22 Improve infrastructure of numeric handling of elements in symbol tables.
370 {
b101ee1a »
2008-01-15 MFH: rename macros
371 ZEND_HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_exists(ht, idx));
e89977f9 »
2003-07-23 Go back to ZE1-like code
372 return zend_hash_exists(ht, arKey, nKeyLength);
cf90932a »
2003-07-22 Improve infrastructure of numeric handling of elements in symbol tables.
373 }
374
00a554b4 »
2009-05-25 MFH(r-1.103) Expand zend_symtable_update_current_key to allow specify…
375 static inline int zend_symtable_update_current_key_ex(HashTable *ht, const char *arKey, uint nKeyLength, int mode, HashPosition *pos)
9ee0707c »
2005-12-05 Fixed bug #35509 (string constant as array key has different behavior…
376 {
00a554b4 »
2009-05-25 MFH(r-1.103) Expand zend_symtable_update_current_key to allow specify…
377 ZEND_HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_update_current_key_ex(ht, HASH_KEY_IS_LONG, NULL, 0, idx, mode, pos));
378 return zend_hash_update_current_key_ex(ht, HASH_KEY_IS_STRING, arKey, nKeyLength, 0, mode, pos);
9ee0707c »
2005-12-05 Fixed bug #35509 (string constant as array key has different behavior…
379 }
00a554b4 »
2009-05-25 MFH(r-1.103) Expand zend_symtable_update_current_key to allow specify…
380 #define zend_symtable_update_current_key(ht,arKey,nKeyLength,mode) \
381 zend_symtable_update_current_key_ex(ht, arKey, nKeyLength, mode, NULL)
382
9ee0707c »
2005-12-05 Fixed bug #35509 (string constant as array key has different behavior…
383
a6172174 »
2000-07-03 Replace macros which begin with an underscore through an appropiately
384 #endif /* ZEND_HASH_H */
333406bd »
2003-02-01 - Added some missing CVS $Id$ tags, headers and footers.
385
386 /*
387 * Local variables:
388 * tab-width: 4
389 * c-basic-offset: 4
390 * indent-tabs-mode: t
391 * End:
392 */
Something went wrong with that request. Please try again.