Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 211 lines (168 sloc) 8.851 kb
573b460 @andigutmans Zend Library
andigutmans authored
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
d2c9e80 @andigutmans - Update copyright year
andigutmans authored
5 | Copyright (c) 1998-2001 Zend Technologies Ltd. (http://www.zend.com) |
573b460 @andigutmans Zend Library
andigutmans authored
6 +----------------------------------------------------------------------+
5e55e47 @zsuraski It's official now...
zsuraski authored
7 | This source file is subject to version 0.92 of the Zend license, |
b5b1117 @zsuraski License update
zsuraski authored
8 | that is bundled with this package in the file LICENSE, and is |
9 | available at through the world-wide-web at |
5e55e47 @zsuraski It's official now...
zsuraski authored
10 | http://www.zend.com/license/0_92.txt. |
b5b1117 @zsuraski License update
zsuraski authored
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
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 +----------------------------------------------------------------------+
18 */
19
a617217 Replace macros which begin with an underscore through an appropiately
Sascha Schumann authored
20 #ifndef ZEND_HASH_H
21 #define ZEND_HASH_H
573b460 @andigutmans Zend Library
andigutmans authored
22
23 #include <sys/types.h>
24
25 #define HASH_KEY_IS_STRING 1
26 #define HASH_KEY_IS_LONG 2
27 #define HASH_KEY_NON_EXISTANT 3
28
29 #define HASH_UPDATE (1<<0)
30 #define HASH_ADD (1<<1)
31 #define HASH_NEXT_INSERT (1<<2)
32
33 #define HASH_DEL_KEY 0
34 #define HASH_DEL_INDEX 1
35
2f8fa8c @andigutmans - Merge faster hash implementation.
andigutmans authored
36 typedef ulong (*hash_func_t)(char *arKey, uint nKeyLength);
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored
37 typedef int (*compare_func_t)(const void *, const void *);
38 typedef void (*sort_func_t)(void *, size_t, register size_t, compare_func_t);
39 typedef void (*dtor_func_t)(void *pDest);
94be61f Made a couple of typedefs for zend_hash_apply_*() calls.
Andrei Zmievski authored
40 typedef int (*apply_func_t)(void *pDest);
41 typedef int (*apply_func_arg_t)(void *pDest, void *argument);
9f51f15 @zsuraski - Stop passing list/plist to internal functions
zsuraski authored
42 typedef void (*copy_ctor_func_t)(void *pElement);
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored
43
9b916e6 rename hastable -> _hashtable to avoid clashes
Thies C. Arntzen authored
44 struct _hashtable;
573b460 @andigutmans Zend Library
andigutmans authored
45
46 typedef struct bucket {
47 ulong h; /* Used for numeric indexing */
48 uint nKeyLength;
49 void *pData;
50 void *pDataPtr;
51 struct bucket *pListNext;
52 struct bucket *pListLast;
53 struct bucket *pNext;
aa73f6b @andigutmans - Hopefully fix the hash problem.
andigutmans authored
54 struct bucket *pLast;
573b460 @andigutmans Zend Library
andigutmans authored
55 char arKey[1]; /* Must be last element */
56 } Bucket;
57
9b916e6 rename hastable -> _hashtable to avoid clashes
Thies C. Arntzen authored
58 typedef struct _hashtable {
573b460 @andigutmans Zend Library
andigutmans authored
59 uint nTableSize;
2f8fa8c @andigutmans - Merge faster hash implementation.
andigutmans authored
60 uint nTableMask;
573b460 @andigutmans Zend Library
andigutmans authored
61 uint nNumOfElements;
62 ulong nNextFreeElement;
63 Bucket *pInternalPointer; /* Used for element traversal */
64 Bucket *pListHead;
65 Bucket *pListTail;
66 Bucket **arBuckets;
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored
67 dtor_func_t pDestructor;
38cdb8e @zsuraski Avoid crashing with recursive applies - limit apply nest level to 3 (…
zsuraski authored
68 zend_bool persistent;
69 unsigned char nApplyCount;
1263932 @zsuraski Disable the hash_apply() protection on hashes that persist across req…
zsuraski authored
70 zend_bool bApplyProtection;
c93a189 if ZEND_DEBUG mode is on we'll now see warnings when a HashTable is …
Thies C. Arntzen authored
71 #if ZEND_DEBUG
72 int inconsistent;
73 #endif
573b460 @andigutmans Zend Library
andigutmans authored
74 } HashTable;
75
a32c54b Introduced a way to traverse hashes through external pointers.
Andrei Zmievski authored
76 typedef Bucket* HashPosition;
77
fd4650b @zsuraski Add zend_hash_get_current_key_type()
zsuraski authored
78 BEGIN_EXTERN_C()
79
573b460 @andigutmans Zend Library
andigutmans authored
80 /* startup/shutdown */
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored
81 ZEND_API int zend_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, int persistent);
1263932 @zsuraski Disable the hash_apply() protection on hashes that persist across req…
zsuraski authored
82 ZEND_API int zend_hash_init_ex(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, int persistent, zend_bool bApplyProtection);
573b460 @andigutmans Zend Library
andigutmans authored
83 ZEND_API void zend_hash_destroy(HashTable *ht);
7b7e72d the resource-lists are now destroyed backwards. this will make sure that
Thies C. Arntzen authored
84 ZEND_API void zend_hash_reverse_destroy(HashTable *ht);
573b460 @andigutmans Zend Library
andigutmans authored
85
86 ZEND_API void zend_hash_clean(HashTable *ht);
87
88 /* additions/updates/changes */
89 ZEND_API int zend_hash_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest,int flag);
90 #define zend_hash_update(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
91 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_UPDATE)
92 #define zend_hash_add(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
93 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_ADD)
94
95 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);
96 #define zend_hash_quick_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
97 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest,HASH_UPDATE)
98 #define zend_hash_quick_add(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
99 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest,HASH_ADD)
100
101 ZEND_API int zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag);
102 #define zend_hash_index_update(ht,h,pData,nDataSize,pDest) \
103 zend_hash_index_update_or_next_insert(ht,h,pData,nDataSize,pDest,HASH_UPDATE)
104 #define zend_hash_next_index_insert(ht,pData,nDataSize,pDest) \
105 zend_hash_index_update_or_next_insert(ht,0,pData,nDataSize,pDest,HASH_NEXT_INSERT)
106
755207a @zsuraski Implement zend_hash_add_empty_element() using the existing infrastruc…
zsuraski authored
107 ZEND_API int zend_hash_add_empty_element(HashTable *ht, char *arKey, uint nKeyLength);
108
746ce67 @andigutmans - Add hash_apply_with_arguments()
andigutmans authored
109 typedef struct _zend_hash_key {
110 char *arKey;
111 uint nKeyLength;
112 ulong h;
113 } zend_hash_key;
114
115
b51aa1f Made an alias for hash apply with arguments.
Andrei Zmievski authored
116 typedef int (*apply_func_args_t)(void *pDest, int num_args, va_list args, zend_hash_key *hash_key);
117
ee08b81 @zsuraski - Make zend_hash_apply() (and friends) reentrant and much, much quicker
zsuraski authored
118 ZEND_API void zend_hash_graceful_destroy(HashTable *ht);
94be61f Made a couple of typedefs for zend_hash_apply_*() calls.
Andrei Zmievski authored
119 ZEND_API void zend_hash_apply(HashTable *ht, apply_func_t apply_func);
120 ZEND_API void zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void *);
1c2893a @zsuraski Minor cleaning
zsuraski authored
121 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
122
573b460 @andigutmans Zend Library
andigutmans authored
123
124
125
126 /* Deletes */
127 ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag);
128 #define zend_hash_del(ht,arKey,nKeyLength) \
129 zend_hash_del_key_or_index(ht,arKey,nKeyLength,0,HASH_DEL_KEY)
130 #define zend_hash_index_del(ht,h) \
131 zend_hash_del_key_or_index(ht,NULL,0,h,HASH_DEL_INDEX)
132
133 ZEND_API ulong zend_get_hash_value(HashTable *ht, char *arKey, uint nKeyLength);
134
135 /* Data retreival */
136 ZEND_API int zend_hash_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData);
137 ZEND_API int zend_hash_quick_find(HashTable *ht, char *arKey, uint nKeyLength, ulong h, void **pData);
138 ZEND_API int zend_hash_index_find(HashTable *ht, ulong h, void **pData);
139
140 /* Misc */
141 ZEND_API int zend_hash_exists(HashTable *ht, char *arKey, uint nKeyLength);
142 ZEND_API int zend_hash_index_exists(HashTable *ht, ulong h);
143 ZEND_API ulong zend_hash_next_free_element(HashTable *ht);
144
145 /* traversing */
ee286fe Make zend_hash_move_forward()/zenv_hash_move_backwards() a little sma…
Andrei Zmievski authored
146 ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
147 ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
36eaad2 @zsuraski Allow get_current_key() not to return the key itself, instead of a du…
zsuraski authored
148 ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong *str_length, ulong *num_index, zend_bool duplicate, HashPosition *pos);
a32c54b Introduced a way to traverse hashes through external pointers.
Andrei Zmievski authored
149 ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
150 ZEND_API int zend_hash_get_current_data_ex(HashTable *ht, void **pData, HashPosition *pos);
151 ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
152 ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
153
154 #define zend_hash_move_forward(ht) \
155 zend_hash_move_forward_ex(ht, NULL)
156 #define zend_hash_move_backwards(ht) \
157 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
158 #define zend_hash_get_current_key(ht, str_index, num_index, duplicate) \
159 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
160 #define zend_hash_get_current_key_type(ht) \
161 zend_hash_get_current_key_type_ex(ht, NULL)
162 #define zend_hash_get_current_data(ht, pData) \
163 zend_hash_get_current_data_ex(ht, pData, NULL)
164 #define zend_hash_internal_pointer_reset(ht) \
165 zend_hash_internal_pointer_reset_ex(ht, NULL)
166 #define zend_hash_internal_pointer_end(ht) \
167 zend_hash_internal_pointer_end_ex(ht, NULL)
573b460 @andigutmans Zend Library
andigutmans authored
168
169 /* Copying, merging and sorting */
9f51f15 @zsuraski - Stop passing list/plist to internal functions
zsuraski authored
170 ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size);
171 ZEND_API void zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite);
e988715 @andigutmans Don't use 'new' symbol
andigutmans authored
172 ZEND_API void zend_hash_merge_ex(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, uint size, zend_bool (*pReplaceOrig)(void *orig, void *p_new));
e956a26 *** empty log message ***
Andrei Zmievski authored
173 ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber);
8ce8324 @zsuraski More TSRMLS_FETCH annihilation
zsuraski authored
174 ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, zend_bool ordered TSRMLS_DC);
9f51f15 @zsuraski - Stop passing list/plist to internal functions
zsuraski authored
175 ZEND_API int zend_hash_minmax(HashTable *ht, int (*compar)(const void *, const void *), int flag, void **pData);
573b460 @andigutmans Zend Library
andigutmans authored
176
177 ZEND_API int zend_hash_num_elements(HashTable *ht);
178
3964c92 Made zend_hash_rehash() callable from outside.
Andrei Zmievski authored
179 ZEND_API int zend_hash_rehash(HashTable *ht);
573b460 @andigutmans Zend Library
andigutmans authored
180
b98acd6 @andigutmans - Move inline_zend_hash_func() to header file
andigutmans authored
181 static inline ulong zend_inline_hash_func(char *arKey, uint nKeyLength)
182 {
183 ulong h = 5381;
184 char *arEnd = arKey + nKeyLength;
185
186 while (arKey < arEnd) {
187 h += (h << 5);
188 h ^= (ulong) *arKey++;
189 }
190 return h;
191 }
192
6cf5e7f @smalyshev No hashpjw anymore, but we have zend_hash_func
smalyshev authored
193 ZEND_API ulong zend_hash_func(char *arKey, uint nKeyLength);
573b460 @andigutmans Zend Library
andigutmans authored
194
9353650 Fix warnings surfacing in maintainer-mode.
Stig S. Bakken authored
195 #if ZEND_DEBUG
573b460 @andigutmans Zend Library
andigutmans authored
196 /* debug */
197 void zend_hash_display_pListTail(HashTable *ht);
198 void zend_hash_display(HashTable *ht);
199 #endif
200
fd4650b @zsuraski Add zend_hash_get_current_key_type()
zsuraski authored
201 END_EXTERN_C()
202
0a14a32 @zsuraski Add useful macros
zsuraski authored
203 #define ZEND_INIT_SYMTABLE(ht) \
204 ZEND_INIT_SYMTABLE_EX(ht, 2, 0)
205
206 #define ZEND_INIT_SYMTABLE_EX(ht, n, persistent) \
207 zend_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
208
209
a617217 Replace macros which begin with an underscore through an appropiately
Sascha Schumann authored
210 #endif /* ZEND_HASH_H */
Something went wrong with that request. Please try again.