File: php3_hash.h

package info (click to toggle)
php3 3%3A3.0.18-0potato1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,736 kB
  • ctags: 11,198
  • sloc: ansic: 108,120; sh: 2,512; php: 2,024; yacc: 1,887; makefile: 1,038; perl: 537; pascal: 238; awk: 90; cpp: 28; sql: 11
file content (156 lines) | stat: -rw-r--r-- 7,107 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* 
   +----------------------------------------------------------------------+
   | PHP HTML Embedded Scripting Language Version 3.0                     |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2000 PHP Development Team (See Credits file)      |
   +----------------------------------------------------------------------+
   | This program is free software; you can redistribute it and/or modify |
   | it under the terms of one of the following licenses:                 |
   |                                                                      |
   |  A) the GNU General Public License as published by the Free Software |
   |     Foundation; either version 2 of the License, or (at your option) |
   |     any later version.                                               |
   |                                                                      |
   |  B) the PHP License as published by the PHP Development Team and     |
   |     included in the distribution in the file: LICENSE                |
   |                                                                      |
   | This program is distributed in the hope that it will be useful,      |
   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
   | GNU General Public License for more details.                         |
   |                                                                      |
   | You should have received a copy of both licenses referred to here.   |
   | If you did not, or have any questions about PHP licensing, please    |
   | contact core@php.net.                                                |
   +----------------------------------------------------------------------+
   | Authors: Andi Gutmans <andi@zend.com>                                |
   |          Zeev Suraski <zeev@zend.com>                                |
   +----------------------------------------------------------------------+
 */


/* $Id: php3_hash.h,v 1.11 2000/04/10 19:29:36 andi Exp $ */


#ifndef _HASH_
#define _HASH_

#include <sys/types.h>

#define HASH_KEY_IS_STRING 1
#define HASH_KEY_IS_LONG 2
#define HASH_KEY_NON_EXISTANT 3

#define HASH_UPDATE 0
#define HASH_ADD 1
#define HASH_NEXT_INSERT 2

#define HASH_DEL_KEY 0
#define HASH_DEL_INDEX 1

struct hashtable;

typedef struct bucket {
	ulong h;						/* Used for numeric indexing */
	char *arKey;
	uint nKeyLength;
	void *pData;
	char bIsPointer;
	struct bucket *pListNext;
	struct bucket *pListLast;
	struct bucket *pNext;
} Bucket;

typedef struct hashtable {
	uint nTableSize;
	uint nHashSizeIndex;
	uint nNumOfElements;
	ulong nNextFreeElement;
	ulong(*pHashFunction) (char *arKey, uint nKeyLength);
	Bucket *pInternalPointer;	/* Used for element traversal */
	Bucket *pListHead;
	Bucket *pListTail;
	Bucket **arBuckets;
	void (*pDestructor) (void *pData);
	unsigned char persistent;
#if DEBUG
	unsigned char indestroy;
#endif
} HashTable;


/* startup/shutdown */
extern PHPAPI int _php3_hash_init(HashTable *ht, uint nSize, ulong(*pHashFunction) (char *arKey, uint nKeyLength), void (*pDestructor) (void *pData), int persistent);
extern PHPAPI void _php3_hash_destroy(HashTable *ht);

/* additions/updates/changes */
extern PHPAPI int _php3_hash_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest,int flag);
#define _php3_hash_update(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
		_php3_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_UPDATE)
#define _php3_hash_add(ht,arKey,nKeyLength,pData,nDataSize,pDest) \
		_php3_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_ADD)

extern PHPAPI int _php3_hash_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag);
#define _php3_hash_index_update(ht,h,pData,nDataSize,pDest) \
		_php3_hash_index_update_or_next_insert(ht,h,pData,nDataSize,pDest,HASH_UPDATE)
#define _php3_hash_next_index_insert(ht,pData,nDataSize,pDest) \
		_php3_hash_index_update_or_next_insert(ht,0,pData,nDataSize,pDest,HASH_NEXT_INSERT)

extern PHPAPI int _php3_hash_pointer_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData);

extern PHPAPI int _php3_hash_pointer_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, int flag);
#define _php3_hash_pointer_index_update(ht,h,pData) \
		_php3_hash_pointer_index_update_or_next_insert(ht,h,pData,HASH_UPDATE)
#define _php3_hash_next_index_pointer_insert(ht,pData) \
        _php3_hash_pointer_index_update_or_next_insert(ht,0,pData,HASH_NEXT_INSERT)
extern PHPAPI void _php3_hash_apply(HashTable *ht,int (*destruct) (void *));
extern PHPAPI void _php3_hash_apply_with_argument(HashTable *ht,int (*destruct) (void *, void *), void *);



/* Deletes */
extern PHPAPI int _php3_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag);
#define _php3_hash_del(ht,arKey,nKeyLength) \
		_php3_hash_del_key_or_index(ht,arKey,nKeyLength,0,HASH_DEL_KEY)
#define _php3_hash_index_del(ht,h) \
		_php3_hash_del_key_or_index(ht,NULL,0,h,HASH_DEL_INDEX)

/* Data retreival */
extern PHPAPI int _php3_hash_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData);
extern PHPAPI int _php3_hash_index_find(HashTable *ht, ulong h, void **pData);

/* Misc */
extern PHPAPI int _php3_hash_exists(HashTable *ht, char *arKey, uint nKeyLength);
extern PHPAPI int _php3_hash_index_exists(HashTable *ht, ulong h);
extern PHPAPI int _php3_hash_is_pointer(HashTable *ht, char *arKey, uint nKeyLength);
extern PHPAPI int _php3_hash_index_is_pointer(HashTable *ht, ulong h);
extern PHPAPI ulong _php3_hash_next_free_element(HashTable *ht);

/* traversing */
extern PHPAPI void _php3_hash_move_forward(HashTable *ht);
extern PHPAPI void _php3_hash_move_backwards(HashTable *ht);
extern PHPAPI int _php3_hash_get_current_key(HashTable *ht, char **str_index, ulong *num_index);
extern PHPAPI int _php3_hash_get_current_data(HashTable *ht, void **pData);
extern PHPAPI void _php3_hash_internal_pointer_reset(HashTable *ht);
extern PHPAPI void _php3_hash_internal_pointer_end(HashTable *ht);

/* internal functions */
extern int if_full_do_resize(HashTable *ht);
extern int _php3_hash_rehash(HashTable *ht);

/* Copying, merging and sorting */
extern PHPAPI void _php3_hash_copy(HashTable **target, HashTable *source, void (*pCopyConstructor) (void *pData), void *tmp, uint size);
extern PHPAPI void _php3_hash_merge(HashTable *target, HashTable *source, void (*pCopyConstructor) (void *pData), void *tmp, uint size);
extern PHPAPI int _php3_hash_sort(HashTable *ht, int (*compar) (const void *, const void *), int renumber);
extern PHPAPI int _php3_hash_minmax(HashTable *ht, int (*compar) (const void *, const void *), int flag, void **pData);

extern PHPAPI int _php3_hash_num_elements(HashTable *ht);


#if DEBUG
/* debug */
extern PHPAPI void _php3_hash_display_pListTail(HashTable *ht);
extern PHPAPI void _php3_hash_display(HashTable *ht);
#endif

#endif							/* _HASH_ */