Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 180 lines (144 sloc) 7.791 kb
573b4602 »
1999-04-07 Zend Library
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski |
6 +----------------------------------------------------------------------+
8d1de13a »
1999-07-19 0.91 update
7 | This source file is subject to version 0.91 of the Zend license, |
b5b11177 »
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 |
8d1de13a »
1999-07-19 0.91 update
10 | http://www.zend.com/license/0_91.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
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 »
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);
40 typedef ulong (*hash_func_t)(char *arKey, uint nKeyLength);
41
573b4602 »
1999-04-07 Zend Library
42 struct hashtable;
43
44 typedef struct bucket {
45 ulong h; /* Used for numeric indexing */
46 uint nKeyLength;
47 void *pData;
48 void *pDataPtr;
49 struct bucket *pListNext;
50 struct bucket *pListLast;
51 struct bucket *pNext;
aa73f6b6 »
2000-01-19 - Hopefully fix the hash problem.
52 struct bucket *pLast;
573b4602 »
1999-04-07 Zend Library
53 char arKey[1]; /* Must be last element */
54 } Bucket;
55
56 typedef struct hashtable {
57 uint nTableSize;
58 uint nHashSizeIndex;
59 uint nNumOfElements;
60 ulong nNextFreeElement;
62114c18 »
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
61 hash_func_t pHashFunction;
573b4602 »
1999-04-07 Zend Library
62 Bucket *pInternalPointer; /* Used for element traversal */
63 Bucket *pListHead;
64 Bucket *pListTail;
65 Bucket **arBuckets;
62114c18 »
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
66 dtor_func_t pDestructor;
573b4602 »
1999-04-07 Zend Library
67 unsigned char persistent;
c93a1890 »
2000-01-15 if ZEND_DEBUG mode is on we'll now see warnings when a HashTable is a…
68 #if ZEND_DEBUG
69 int inconsistent;
70 #endif
573b4602 »
1999-04-07 Zend Library
71 } HashTable;
72
fd4650b5 »
1999-06-07 Add zend_hash_get_current_key_type()
73 BEGIN_EXTERN_C()
74
573b4602 »
1999-04-07 Zend Library
75 /* startup/shutdown */
62114c18 »
2000-01-17 Destructors no longer return ints, the low level problem it was inten…
76 ZEND_API int zend_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, int persistent);
573b4602 »
1999-04-07 Zend Library
77 ZEND_API void zend_hash_destroy(HashTable *ht);
78
79 ZEND_API void zend_hash_clean(HashTable *ht);
80
81 /* additions/updates/changes */
82 ZEND_API int zend_hash_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest,int flag);
83 #define zend_hash_update(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
84 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_UPDATE)
85 #define zend_hash_add(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
86 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_ADD)
87 #define zend_hash_update_ptr(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
88 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,0,pDest,(HASH_UPDATE|HASH_ADD_PTR))
89
90 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);
91 #define zend_hash_quick_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
92 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest,HASH_UPDATE)
93 #define zend_hash_quick_add(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
94 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest,HASH_ADD)
95 #define zend_hash_quick_update_ptr(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
96 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,0,pDest,HASH_UPDATE|HASH_ADD_PTR)
97
98 ZEND_API int zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag);
99 #define zend_hash_index_update(ht,h,pData,nDataSize,pDest) \
100 zend_hash_index_update_or_next_insert(ht,h,pData,nDataSize,pDest,HASH_UPDATE)
101 #define zend_hash_next_index_insert(ht,pData,nDataSize,pDest) \
102 zend_hash_index_update_or_next_insert(ht,0,pData,nDataSize,pDest,HASH_NEXT_INSERT)
103 #define zend_hash_next_index_insert_ptr(ht,pData,nDataSize,pDest) \
104 zend_hash_index_update_or_next_insert(ht,0,pData,nDataSize,pDest,HASH_NEXT_INSERT|HASH_ADD_PTR)
105
106 ZEND_API int zend_hash_pointer_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData);
107
746ce67b »
1999-08-25 - Add hash_apply_with_arguments()
108 typedef struct _zend_hash_key {
109 char *arKey;
110 uint nKeyLength;
111 ulong h;
112 } zend_hash_key;
113
114
115 #define ZEND_STD_HASH_APPLIER \
116 int (*)(void *element, int num_args, va_list args, zend_hash_key *hash_key)
117
573b4602 »
1999-04-07 Zend Library
118 ZEND_API int zend_hash_pointer_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, int flag);
119 #define zend_hash_pointer_index_update(ht,h,pData) \
120 zend_hash_pointer_index_update_or_next_insert(ht,h,pData,HASH_UPDATE)
121 #define zend_hash_next_index_pointer_insert(ht,pData) \
122 zend_hash_pointer_index_update_or_next_insert(ht,0,pData,HASH_NEXT_INSERT)
ee08b81a »
2000-01-16 - Make zend_hash_apply() (and friends) reentrant and much, much quicker
123 ZEND_API void zend_hash_graceful_destroy(HashTable *ht);
746ce67b »
1999-08-25 - Add hash_apply_with_arguments()
124 ZEND_API void zend_hash_apply(HashTable *ht,int (*destruct)(void *));
125 ZEND_API void zend_hash_apply_with_argument(HashTable *ht,int (*destruct)(void *, void *), void *);
126 ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, ZEND_STD_HASH_APPLIER, int, ...);
127
573b4602 »
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 */
151 ZEND_API void zend_hash_move_forward(HashTable *ht);
152 ZEND_API void zend_hash_move_backwards(HashTable *ht);
153 ZEND_API int zend_hash_get_current_key(HashTable *ht, char **str_index, ulong *num_index);
fd4650b5 »
1999-06-07 Add zend_hash_get_current_key_type()
154 ZEND_API int zend_hash_get_current_key_type(HashTable *ht);
573b4602 »
1999-04-07 Zend Library
155 ZEND_API int zend_hash_get_current_data(HashTable *ht, void **pData);
156 ZEND_API void zend_hash_internal_pointer_reset(HashTable *ht);
157 ZEND_API void zend_hash_internal_pointer_end(HashTable *ht);
158
159 /* Copying, merging and sorting */
160 ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, void (*pCopyConstructor) (void *pData), void *tmp, uint size);
bcc1337d »
1999-05-29 Support overwrite mode in zend_hash_merge()
161 ZEND_API void zend_hash_merge(HashTable *target, HashTable *source, void (*pCopyConstructor) (void *pData), void *tmp, uint size, int overwrite);
e956a266 »
1999-10-15 *** empty log message ***
162 ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber);
573b4602 »
1999-04-07 Zend Library
163 ZEND_API int zend_hash_minmax(HashTable *ht, int (*compar) (const void *, const void *), int flag, void **pData);
164
165 ZEND_API int zend_hash_num_elements(HashTable *ht);
166
3964c92f »
1999-11-04 Made zend_hash_rehash() callable from outside.
167 ZEND_API int zend_hash_rehash(HashTable *ht);
573b4602 »
1999-04-07 Zend Library
168
169 ZEND_API ulong hashpjw(char *arKey, uint nKeyLength);
170
93536507 »
1999-12-01 Fix warnings surfacing in maintainer-mode.
171 #if ZEND_DEBUG
573b4602 »
1999-04-07 Zend Library
172 /* debug */
173 void zend_hash_display_pListTail(HashTable *ht);
174 void zend_hash_display(HashTable *ht);
175 #endif
176
fd4650b5 »
1999-06-07 Add zend_hash_get_current_key_type()
177 END_EXTERN_C()
178
573b4602 »
1999-04-07 Zend Library
179 #endif /* _HASH_ */
Something went wrong with that request. Please try again.