Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 161 lines (129 sloc) 7.309 kB
573b460 @andigutmans Zend Library
andigutmans authored
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski |
6 +----------------------------------------------------------------------+
b5b1117 @zsuraski License update
zsuraski authored
7 | This source file is subject to version 0.90 of the Zend license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available at through the world-wide-web at |
10 | http://www.zend.com/license/0_90.txt. |
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
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
37 struct hashtable;
38
39 typedef struct bucket {
40 ulong h; /* Used for numeric indexing */
41 uint nKeyLength;
42 void *pData;
43 void *pDataPtr;
44 char bIsPointer;
45 struct bucket *pListNext;
46 struct bucket *pListLast;
47 struct bucket *pNext;
48 char arKey[1]; /* Must be last element */
49 } Bucket;
50
51 typedef struct hashtable {
52 uint nTableSize;
53 uint nHashSizeIndex;
54 uint nNumOfElements;
55 ulong nNextFreeElement;
56 ulong(*pHashFunction) (char *arKey, uint nKeyLength);
57 Bucket *pInternalPointer; /* Used for element traversal */
58 Bucket *pListHead;
59 Bucket *pListTail;
60 Bucket **arBuckets;
81d901b @zsuraski Step 1 in nuking the garbage collector:
zsuraski authored
61 int (*pDestructor) (void *pData);
573b460 @andigutmans Zend Library
andigutmans authored
62 unsigned char persistent;
63 } HashTable;
64
65
fd4650b @zsuraski Add zend_hash_get_current_key_type()
zsuraski authored
66 BEGIN_EXTERN_C()
67
573b460 @andigutmans Zend Library
andigutmans authored
68 /* startup/shutdown */
81d901b @zsuraski Step 1 in nuking the garbage collector:
zsuraski authored
69 ZEND_API int zend_hash_init(HashTable *ht, uint nSize, ulong(*pHashFunction) (char *arKey, uint nKeyLength), int (*pDestructor) (void *pData), int persistent);
573b460 @andigutmans Zend Library
andigutmans authored
70 ZEND_API void zend_hash_destroy(HashTable *ht);
71
72 ZEND_API void zend_hash_clean(HashTable *ht);
73
74 /* additions/updates/changes */
75 ZEND_API int zend_hash_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest,int flag);
76 #define zend_hash_update(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
77 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_UPDATE)
78 #define zend_hash_add(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
79 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_ADD)
80 #define zend_hash_update_ptr(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
81 zend_hash_add_or_update(ht,arKey,nKeyLength,pData,0,pDest,(HASH_UPDATE|HASH_ADD_PTR))
82
83 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);
84 #define zend_hash_quick_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
85 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest,HASH_UPDATE)
86 #define zend_hash_quick_add(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
87 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest,HASH_ADD)
88 #define zend_hash_quick_update_ptr(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \
89 zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,0,pDest,HASH_UPDATE|HASH_ADD_PTR)
90
91 ZEND_API int zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag);
92 #define zend_hash_index_update(ht,h,pData,nDataSize,pDest) \
93 zend_hash_index_update_or_next_insert(ht,h,pData,nDataSize,pDest,HASH_UPDATE)
94 #define zend_hash_next_index_insert(ht,pData,nDataSize,pDest) \
95 zend_hash_index_update_or_next_insert(ht,0,pData,nDataSize,pDest,HASH_NEXT_INSERT)
96 #define zend_hash_next_index_insert_ptr(ht,pData,nDataSize,pDest) \
97 zend_hash_index_update_or_next_insert(ht,0,pData,nDataSize,pDest,HASH_NEXT_INSERT|HASH_ADD_PTR)
98
99 ZEND_API int zend_hash_pointer_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData);
100
101 ZEND_API int zend_hash_pointer_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, int flag);
102 #define zend_hash_pointer_index_update(ht,h,pData) \
103 zend_hash_pointer_index_update_or_next_insert(ht,h,pData,HASH_UPDATE)
104 #define zend_hash_next_index_pointer_insert(ht,pData) \
105 zend_hash_pointer_index_update_or_next_insert(ht,0,pData,HASH_NEXT_INSERT)
106 ZEND_API void zend_hash_apply(HashTable *ht,int (*destruct) (void *));
107 ZEND_API void zend_hash_apply_with_argument(HashTable *ht,int (*destruct) (void *, void *), void *);
108
109
110
111 /* Deletes */
112 ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag);
113 #define zend_hash_del(ht,arKey,nKeyLength) \
114 zend_hash_del_key_or_index(ht,arKey,nKeyLength,0,HASH_DEL_KEY)
115 #define zend_hash_index_del(ht,h) \
116 zend_hash_del_key_or_index(ht,NULL,0,h,HASH_DEL_INDEX)
117
118 ZEND_API ulong zend_get_hash_value(HashTable *ht, char *arKey, uint nKeyLength);
119
120 /* Data retreival */
121 ZEND_API int zend_hash_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData);
122 ZEND_API int zend_hash_quick_find(HashTable *ht, char *arKey, uint nKeyLength, ulong h, void **pData);
123 ZEND_API int zend_hash_index_find(HashTable *ht, ulong h, void **pData);
124
125 /* Misc */
126 ZEND_API int zend_hash_exists(HashTable *ht, char *arKey, uint nKeyLength);
127 ZEND_API int zend_hash_index_exists(HashTable *ht, ulong h);
128 ZEND_API int zend_hash_is_pointer(HashTable *ht, char *arKey, uint nKeyLength);
129 ZEND_API int zend_hash_index_is_pointer(HashTable *ht, ulong h);
130 ZEND_API ulong zend_hash_next_free_element(HashTable *ht);
131
132 /* traversing */
133 ZEND_API void zend_hash_move_forward(HashTable *ht);
134 ZEND_API void zend_hash_move_backwards(HashTable *ht);
135 ZEND_API int zend_hash_get_current_key(HashTable *ht, char **str_index, ulong *num_index);
fd4650b @zsuraski Add zend_hash_get_current_key_type()
zsuraski authored
136 ZEND_API int zend_hash_get_current_key_type(HashTable *ht);
573b460 @andigutmans Zend Library
andigutmans authored
137 ZEND_API int zend_hash_get_current_data(HashTable *ht, void **pData);
138 ZEND_API void zend_hash_internal_pointer_reset(HashTable *ht);
139 ZEND_API void zend_hash_internal_pointer_end(HashTable *ht);
140
141 /* Copying, merging and sorting */
142 ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, void (*pCopyConstructor) (void *pData), void *tmp, uint size);
bcc1337 @zsuraski Support overwrite mode in zend_hash_merge()
zsuraski authored
143 ZEND_API void zend_hash_merge(HashTable *target, HashTable *source, void (*pCopyConstructor) (void *pData), void *tmp, uint size, int overwrite);
573b460 @andigutmans Zend Library
andigutmans authored
144 ZEND_API int zend_hash_sort(HashTable *ht, int (*compar) (const void *, const void *), int renumber);
145 ZEND_API int zend_hash_minmax(HashTable *ht, int (*compar) (const void *, const void *), int flag, void **pData);
146
147 ZEND_API int zend_hash_num_elements(HashTable *ht);
148
149
150 ZEND_API ulong hashpjw(char *arKey, uint nKeyLength);
151
152 #if DEBUG
153 /* debug */
154 void zend_hash_display_pListTail(HashTable *ht);
155 void zend_hash_display(HashTable *ht);
156 #endif
157
fd4650b @zsuraski Add zend_hash_get_current_key_type()
zsuraski authored
158 END_EXTERN_C()
159
573b460 @andigutmans Zend Library
andigutmans authored
160 #endif /* _HASH_ */
Something went wrong with that request. Please try again.