Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 194 lines (158 sloc) 8.457 kb
573b4602 » andigutmans
1999-04-07 Zend Library
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5e55e47f » zsuraski
2000-03-06 It's official now...
5 | Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
573b4602 » andigutmans
1999-04-07 Zend Library
6 +----------------------------------------------------------------------+
5e55e47f » zsuraski
2000-03-06 It's official now...
7 | This source file is subject to version 0.92 of the Zend license, |
b5b11177 » zsuraski
1999-07-16 License update
8 | that is bundled with this package in the file LICENSE, and is |
9 | available at through the world-wide-web at |
5e55e47f » zsuraski
2000-03-06 It's official now...
10 | http://www.zend.com/license/0_92.txt. |
b5b11177 » zsuraski
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 » andigutmans
1999-04-07 Zend Library
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 +----------------------------------------------------------------------+
18 */
19
20 #ifndef _HASH_
21 #define _HASH_
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 #define HASH_ADD_PTR (1<<3)
33
34 #define HASH_DEL_KEY 0
35 #define HASH_DEL_INDEX 1
36
62114c18 » zsuraski
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
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);
94be61fd » Andrei Zmievski
2000-02-11 Made a couple of typedefs for zend_hash_apply_*() calls.
40 typedef int (*apply_func_t)(void *pDest);
41 typedef int (*apply_func_arg_t)(void *pDest, void *argument);
62114c18 » zsuraski
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
42 typedef ulong (*hash_func_t)(char *arKey, uint nKeyLength);
9f51f154 » zsuraski
2000-02-05 - Stop passing list/plist to internal functions
43 typedef void (*copy_ctor_func_t)(void *pElement);
62114c18 » zsuraski
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
44
573b4602 » andigutmans
1999-04-07 Zend Library
45 struct hashtable;
46
47 typedef struct bucket {
48 ulong h; /* Used for numeric indexing */
49 uint nKeyLength;
50 void *pData;
51 void *pDataPtr;
52 struct bucket *pListNext;
53 struct bucket *pListLast;
54 struct bucket *pNext;
aa73f6b6 » andigutmans
2000-01-19 - Hopefully fix the hash problem.
55 struct bucket *pLast;
573b4602 » andigutmans
1999-04-07 Zend Library
56 char arKey[1]; /* Must be last element */
57 } Bucket;
58
59 typedef struct hashtable {
60 uint nTableSize;
61 uint nHashSizeIndex;
62 uint nNumOfElements;
63 ulong nNextFreeElement;
62114c18 » zsuraski
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
64 hash_func_t pHashFunction;
573b4602 » andigutmans
1999-04-07 Zend Library
65 Bucket *pInternalPointer; /* Used for element traversal */
66 Bucket *pListHead;
67 Bucket *pListTail;
68 Bucket **arBuckets;
62114c18 » zsuraski
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
69 dtor_func_t pDestructor;
573b4602 » andigutmans
1999-04-07 Zend Library
70 unsigned char persistent;
c93a1890 » Thies C. Arntzen
2000-01-15 if ZEND_DEBUG mode is on we'll now see warnings when a HashTable is a…
71 #if ZEND_DEBUG
72 int inconsistent;
73 #endif
573b4602 » andigutmans
1999-04-07 Zend Library
74 } HashTable;
75
a32c54bd » Andrei Zmievski
2000-03-13 Introduced a way to traverse hashes through external pointers.
76 typedef Bucket* HashPosition;
77
fd4650b5 » zsuraski
1999-06-07 Add zend_hash_get_current_key_type()
78 BEGIN_EXTERN_C()
79
573b4602 » andigutmans
1999-04-07 Zend Library
80 /* startup/shutdown */
62114c18 » zsuraski
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
81 ZEND_API int zend_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, int persistent);
573b4602 » andigutmans
1999-04-07 Zend Library
82 ZEND_API void zend_hash_destroy(HashTable *ht);
83
84 ZEND_API void zend_hash_clean(HashTable *ht);
85
86 /* additions/updates/changes */
87 ZEND_API int zend_hash_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest,int flag);
88 #define zend_hash_update(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
89 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_UPDATE)
90 #define zend_hash_add(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
91 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_ADD)
92 #define zend_hash_update_ptr(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
93 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,0,pDest,(HASH_UPDATE|HASH_ADD_PTR))
bb302a75 » andigutmans
2000-02-13 - Make startup a bit faster by changing some hash_update()'s and hash…
94 #define zend_hash_add_ptr(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
95 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,(HASH_ADD|HASH_ADD_PTR))
573b4602 » andigutmans
1999-04-07 Zend Library
96
97 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);
98 #define zend_hash_quick_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
99 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest,HASH_UPDATE)
100 #define zend_hash_quick_add(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
101 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest,HASH_ADD)
102 #define zend_hash_quick_update_ptr(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
103 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,0,pDest,HASH_UPDATE|HASH_ADD_PTR)
104
105 ZEND_API int zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag);
106 #define zend_hash_index_update(ht,h,pData,nDataSize,pDest) \
107 zend_hash_index_update_or_next_insert(ht,h,pData,nDataSize,pDest,HASH_UPDATE)
108 #define zend_hash_next_index_insert(ht,pData,nDataSize,pDest) \
109 zend_hash_index_update_or_next_insert(ht,0,pData,nDataSize,pDest,HASH_NEXT_INSERT)
110 #define zend_hash_next_index_insert_ptr(ht,pData,nDataSize,pDest) \
111 zend_hash_index_update_or_next_insert(ht,0,pData,nDataSize,pDest,HASH_NEXT_INSERT|HASH_ADD_PTR)
112
746ce67b » andigutmans
1999-08-25 - Add hash_apply_with_arguments()
113 typedef struct _zend_hash_key {
114 char *arKey;
115 uint nKeyLength;
116 ulong h;
117 } zend_hash_key;
118
119
120 #define ZEND_STD_HASH_APPLIER \
121 int (*)(void *element, int num_args, va_list args, zend_hash_key *hash_key)
122
ee08b81a » zsuraski
2000-01-16 - Make zend_hash_apply() (and friends) reentrant and much, much quicker
123 ZEND_API void zend_hash_graceful_destroy(HashTable *ht);
94be61fd » Andrei Zmievski
2000-02-11 Made a couple of typedefs for zend_hash_apply_*() calls.
124 ZEND_API void zend_hash_apply(HashTable *ht, apply_func_t apply_func);
125 ZEND_API void zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void *);
746ce67b » andigutmans
1999-08-25 - Add hash_apply_with_arguments()
126 ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, ZEND_STD_HASH_APPLIER, int, ...);
127
573b4602 » andigutmans
1999-04-07 Zend Library
128
129
130
131 /* Deletes */
132 ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag);
133 #define zend_hash_del(ht,arKey,nKeyLength) \
134 zend_hash_del_key_or_index(ht,arKey,nKeyLength,0,HASH_DEL_KEY)
135 #define zend_hash_index_del(ht,h) \
136 zend_hash_del_key_or_index(ht,NULL,0,h,HASH_DEL_INDEX)
137
138 ZEND_API ulong zend_get_hash_value(HashTable *ht, char *arKey, uint nKeyLength);
139
140 /* Data retreival */
141 ZEND_API int zend_hash_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData);
142 ZEND_API int zend_hash_quick_find(HashTable *ht, char *arKey, uint nKeyLength, ulong h, void **pData);
143 ZEND_API int zend_hash_index_find(HashTable *ht, ulong h, void **pData);
144
145 /* Misc */
146 ZEND_API int zend_hash_exists(HashTable *ht, char *arKey, uint nKeyLength);
147 ZEND_API int zend_hash_index_exists(HashTable *ht, ulong h);
148 ZEND_API ulong zend_hash_next_free_element(HashTable *ht);
149
150 /* traversing */
ee286feb » Andrei Zmievski
2000-03-15 Make zend_hash_move_forward()/zenv_hash_move_backwards() a little sma…
151 ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
152 ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
a32c54bd » Andrei Zmievski
2000-03-13 Introduced a way to traverse hashes through external pointers.
153 ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong *num_index, HashPosition *pos);
154 ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
155 ZEND_API int zend_hash_get_current_data_ex(HashTable *ht, void **pData, HashPosition *pos);
156 ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
157 ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos);
158
159 #define zend_hash_move_forward(ht) \
160 zend_hash_move_forward_ex(ht, NULL)
161 #define zend_hash_move_backwards(ht) \
162 zend_hash_move_backwards_ex(ht, NULL)
163 #define zend_hash_get_current_key(ht, str_index, num_index) \
164 zend_hash_get_current_key_ex(ht, str_index, num_index, NULL)
165 #define zend_hash_get_current_key_type(ht) \
166 zend_hash_get_current_key_type_ex(ht, NULL)
167 #define zend_hash_get_current_data(ht, pData) \
168 zend_hash_get_current_data_ex(ht, pData, NULL)
169 #define zend_hash_internal_pointer_reset(ht) \
170 zend_hash_internal_pointer_reset_ex(ht, NULL)
171 #define zend_hash_internal_pointer_end(ht) \
172 zend_hash_internal_pointer_end_ex(ht, NULL)
573b4602 » andigutmans
1999-04-07 Zend Library
173
174 /* Copying, merging and sorting */
9f51f154 » zsuraski
2000-02-05 - Stop passing list/plist to internal functions
175 ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size);
176 ZEND_API void zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite);
e956a266 » Andrei Zmievski
1999-10-15 *** empty log message ***
177 ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber);
9f51f154 » zsuraski
2000-02-05 - Stop passing list/plist to internal functions
178 ZEND_API int zend_hash_minmax(HashTable *ht, int (*compar)(const void *, const void *), int flag, void **pData);
573b4602 » andigutmans
1999-04-07 Zend Library
179
180 ZEND_API int zend_hash_num_elements(HashTable *ht);
181
3964c92f » Andrei Zmievski
1999-11-04 Made zend_hash_rehash() callable from outside.
182 ZEND_API int zend_hash_rehash(HashTable *ht);
573b4602 » andigutmans
1999-04-07 Zend Library
183
184 ZEND_API ulong hashpjw(char *arKey, uint nKeyLength);
185
93536507 » Stig S. Bakken
1999-12-01 Fix warnings surfacing in maintainer-mode.
186 #if ZEND_DEBUG
573b4602 » andigutmans
1999-04-07 Zend Library
187 /* debug */
188 void zend_hash_display_pListTail(HashTable *ht);
189 void zend_hash_display(HashTable *ht);
190 #endif
191
fd4650b5 » zsuraski
1999-06-07 Add zend_hash_get_current_key_type()
192 END_EXTERN_C()
193
573b4602 » andigutmans
1999-04-07 Zend Library
194 #endif /* _HASH_ */
Something went wrong with that request. Please try again.