Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 199 lines (158 sloc) 8.402 kb
573b460 @andigutmans Zend Library
andigutmans authored
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5e55e47 @zsuraski It's official now...
zsuraski authored
5 | Copyright (c) 1998-2000 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
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored
36 typedef int (*compare_func_t)(const void *, const void *);
37 typedef void (*sort_func_t)(void *, size_t, register size_t, compare_func_t);
38 typedef void (*dtor_func_t)(void *pDest);
94be61f Made a couple of typedefs for zend_hash_apply_*() calls.
Andrei Zmievski authored
39 typedef int (*apply_func_t)(void *pDest);
40 typedef int (*apply_func_arg_t)(void *pDest, void *argument);
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored
41 typedef ulong (*hash_func_t)(char *arKey, uint nKeyLength);
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;
60 uint nHashSizeIndex;
61 uint nNumOfElements;
62 ulong nNextFreeElement;
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored
63 hash_func_t pHashFunction;
573b460 @andigutmans Zend Library
andigutmans authored
64 Bucket *pInternalPointer; /* Used for element traversal */
65 Bucket *pListHead;
66 Bucket *pListTail;
67 Bucket **arBuckets;
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored
68 dtor_func_t pDestructor;
38cdb8e @zsuraski Avoid crashing with recursive applies - limit apply nest level to 3 (…
zsuraski authored
69 zend_bool persistent;
70 unsigned char nApplyCount;
1263932 @zsuraski Disable the hash_apply() protection on hashes that persist across req…
zsuraski authored
71 zend_bool bApplyProtection;
c93a189 if ZEND_DEBUG mode is on we'll now see warnings when a HashTable is …
Thies C. Arntzen authored
72 #if ZEND_DEBUG
73 int inconsistent;
74 #endif
573b460 @andigutmans Zend Library
andigutmans authored
75 } HashTable;
76
a32c54b Introduced a way to traverse hashes through external pointers.
Andrei Zmievski authored
77 typedef Bucket* HashPosition;
78
fd4650b @zsuraski Add zend_hash_get_current_key_type()
zsuraski authored
79 BEGIN_EXTERN_C()
80
573b460 @andigutmans Zend Library
andigutmans authored
81 /* startup/shutdown */
62114c1 @zsuraski Destructors no longer return ints, the low level problem it was inten…
zsuraski authored
82 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
83 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
84 ZEND_API void zend_hash_destroy(HashTable *ht);
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
746ce67 @andigutmans - Add hash_apply_with_arguments()
andigutmans authored
107 typedef struct _zend_hash_key {
108 char *arKey;
109 uint nKeyLength;
110 ulong h;
111 } zend_hash_key;
112
113
b51aa1f Made an alias for hash apply with arguments.
Andrei Zmievski authored
114 typedef int (*apply_func_args_t)(void *pDest, int num_args, va_list args, zend_hash_key *hash_key);
115
746ce67 @andigutmans - Add hash_apply_with_arguments()
andigutmans authored
116 #define ZEND_STD_HASH_APPLIER \
117 int (*)(void *element, int num_args, va_list args, zend_hash_key *hash_key)
118
ee08b81 @zsuraski - Make zend_hash_apply() (and friends) reentrant and much, much quicker
zsuraski authored
119 ZEND_API void zend_hash_graceful_destroy(HashTable *ht);
94be61f Made a couple of typedefs for zend_hash_apply_*() calls.
Andrei Zmievski authored
120 ZEND_API void zend_hash_apply(HashTable *ht, apply_func_t apply_func);
121 ZEND_API void zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void *);
746ce67 @andigutmans - Add hash_apply_with_arguments()
andigutmans authored
122 ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, ZEND_STD_HASH_APPLIER, int, ...);
123
573b460 @andigutmans Zend Library
andigutmans authored
124
125
126
127 /* Deletes */
128 ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag);
129 #define zend_hash_del(ht,arKey,nKeyLength) \
130 zend_hash_del_key_or_index(ht,arKey,nKeyLength,0,HASH_DEL_KEY)
131 #define zend_hash_index_del(ht,h) \
132 zend_hash_del_key_or_index(ht,NULL,0,h,HASH_DEL_INDEX)
133
134 ZEND_API ulong zend_get_hash_value(HashTable *ht, char *arKey, uint nKeyLength);
135
136 /* Data retreival */
137 ZEND_API int zend_hash_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData);
138 ZEND_API int zend_hash_quick_find(HashTable *ht, char *arKey, uint nKeyLength, ulong h, void **pData);
139 ZEND_API int zend_hash_index_find(HashTable *ht, ulong h, void **pData);
140
141 /* Misc */
142 ZEND_API int zend_hash_exists(HashTable *ht, char *arKey, uint nKeyLength);
143 ZEND_API int zend_hash_index_exists(HashTable *ht, ulong h);
144 ZEND_API ulong zend_hash_next_free_element(HashTable *ht);
145
146 /* traversing */
ee286fe Make zend_hash_move_forward()/zenv_hash_move_backwards() a little sma…
Andrei Zmievski authored
147 ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
148 ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
8ca13c9 @zsuraski Change zend_hash_get_current_key_ex() to also return the string length
zsuraski authored
149 ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong *str_length, ulong *num_index, HashPosition *pos);
a32c54b Introduced a way to traverse hashes through external pointers.
Andrei Zmievski authored
150 ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
151 ZEND_API int zend_hash_get_current_data_ex(HashTable *ht, void **pData, HashPosition *pos);
152 ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
153 ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
154
155 #define zend_hash_move_forward(ht) \
156 zend_hash_move_forward_ex(ht, NULL)
157 #define zend_hash_move_backwards(ht) \
158 zend_hash_move_backwards_ex(ht, NULL)
159 #define zend_hash_get_current_key(ht, str_index, num_index) \
8ca13c9 @zsuraski Change zend_hash_get_current_key_ex() to also return the string length
zsuraski authored
160 zend_hash_get_current_key_ex(ht, str_index, NULL, num_index, NULL)
a32c54b Introduced a way to traverse hashes through external pointers.
Andrei Zmievski authored
161 #define zend_hash_get_current_key_type(ht) \
162 zend_hash_get_current_key_type_ex(ht, NULL)
163 #define zend_hash_get_current_data(ht, pData) \
164 zend_hash_get_current_data_ex(ht, pData, NULL)
165 #define zend_hash_internal_pointer_reset(ht) \
166 zend_hash_internal_pointer_reset_ex(ht, NULL)
167 #define zend_hash_internal_pointer_end(ht) \
168 zend_hash_internal_pointer_end_ex(ht, NULL)
573b460 @andigutmans Zend Library
andigutmans authored
169
170 /* Copying, merging and sorting */
9f51f15 @zsuraski - Stop passing list/plist to internal functions
zsuraski authored
171 ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size);
172 ZEND_API void zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite);
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);
bfac463 @zsuraski - Support unordered hash comparisons
zsuraski authored
174 ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, zend_bool ordered);
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
181 ZEND_API ulong hashpjw(char *arKey, uint nKeyLength);
182
9353650 Fix warnings surfacing in maintainer-mode.
Stig S. Bakken authored
183 #if ZEND_DEBUG
573b460 @andigutmans Zend Library
andigutmans authored
184 /* debug */
185 void zend_hash_display_pListTail(HashTable *ht);
186 void zend_hash_display(HashTable *ht);
187 #endif
188
fd4650b @zsuraski Add zend_hash_get_current_key_type()
zsuraski authored
189 END_EXTERN_C()
190
0a14a32 @zsuraski Add useful macros
zsuraski authored
191 #define ZEND_INIT_SYMTABLE(ht) \
192 ZEND_INIT_SYMTABLE_EX(ht, 2, 0)
193
194 #define ZEND_INIT_SYMTABLE_EX(ht, n, persistent) \
195 zend_hash_init(ht, n, NULL, ZVAL_PTR_DTOR, persistent)
196
197
a617217 Replace macros which begin with an underscore through an appropiately
Sascha Schumann authored
198 #endif /* ZEND_HASH_H */
Something went wrong with that request. Please try again.