hash.h 6.45 KB
Newer Older
1
/*
2
 * Summary: Chained hash tables
Daniel Veillard's avatar
Daniel Veillard committed
3
4
 * Description: This module implements the hash table support used in
 *		various places in the library.
5
 *
6
 * Copy: See Copyright for the status of this software.
7
 *
8
 * Author: Bjorn Reese <bjorn.reese@systematic.dk>
9
10
11
12
13
14
15
16
17
18
 */

#ifndef __XML_HASH_H__
#define __XML_HASH_H__

#ifdef __cplusplus
extern "C" {
#endif

/*
19
 * The hash table.
20
21
22
23
 */
typedef struct _xmlHashTable xmlHashTable;
typedef xmlHashTable *xmlHashTablePtr;

24
25
26
27
28
29
#ifdef __cplusplus
}
#endif

#include <libxml/xmlversion.h>
#include <libxml/parser.h>
30
#include <libxml/dict.h>
31
32
33
34
35

#ifdef __cplusplus
extern "C" {
#endif

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Recent version of gcc produce a warning when a function pointer is assigned
 * to an object pointer, or vice versa.  The following macro is a dirty hack
 * to allow suppression of the warning.  If your architecture has function
 * pointers which are a different size than a void pointer, there may be some
 * serious trouble within the library.
 */
/**
 * XML_CAST_FPTR:
 * @fptr:  pointer to a function
 *
 * Macro to do a casting from an object pointer to a
 * function pointer without encountering a warning from
 * gcc
 *
51
52
53
 * #define XML_CAST_FPTR(fptr) (*(void **)(&fptr))
 * This macro violated ISO C aliasing rules (gcc4 on s390 broke)
 * so it is disabled now
54
 */
55
56
57

#define XML_CAST_FPTR(fptr) fptr

58

59
60
61
/*
 * function types:
 */
62
63
64
65
66
/**
 * xmlHashDeallocator:
 * @payload:  the data in the hash
 * @name:  the name associated
 *
67
 * Callback to free data from a hash.
68
 */
Nick Wellnhofer's avatar
Nick Wellnhofer committed
69
typedef void (*xmlHashDeallocator)(void *payload, const xmlChar *name);
70
71
72
73
74
/**
 * xmlHashCopier:
 * @payload:  the data in the hash
 * @name:  the name associated
 *
75
 * Callback to copy data from a hash.
76
 *
77
 * Returns a copy of the data or NULL in case of error.
78
 */
Nick Wellnhofer's avatar
Nick Wellnhofer committed
79
typedef void *(*xmlHashCopier)(void *payload, const xmlChar *name);
80
81
82
83
84
85
/**
 * xmlHashScanner:
 * @payload:  the data in the hash
 * @data:  extra scannner data
 * @name:  the name associated
 *
86
 * Callback when scanning data in a hash with the simple scanner.
87
 */
Nick Wellnhofer's avatar
Nick Wellnhofer committed
88
typedef void (*xmlHashScanner)(void *payload, void *data, const xmlChar *name);
89
90
91
92
93
94
95
96
/**
 * xmlHashScannerFull:
 * @payload:  the data in the hash
 * @data:  extra scannner data
 * @name:  the name associated
 * @name2:  the second name associated
 * @name3:  the third name associated
 *
97
 * Callback when scanning data in a hash with the full scanner.
98
 */
99
100
101
typedef void (*xmlHashScannerFull)(void *payload, void *data,
				   const xmlChar *name, const xmlChar *name2,
				   const xmlChar *name3);
102
103

/*
104
 * Constructor and destructor.
105
 */
106
107
XMLPUBFUN xmlHashTablePtr XMLCALL
			xmlHashCreate	(int size);
108
109
110
XMLPUBFUN xmlHashTablePtr XMLCALL
			xmlHashCreateDict(int size,
					 xmlDictPtr dict);
Daniel Veillard's avatar
Daniel Veillard committed
111
XMLPUBFUN void XMLCALL
112
			xmlHashFree	(xmlHashTablePtr table,
113
					 xmlHashDeallocator f);
Nick Wellnhofer's avatar
Nick Wellnhofer committed
114
115
116
XMLPUBFUN void XMLCALL
			xmlHashDefaultDeallocator(void *entry,
					 const xmlChar *name);
117
118

/*
119
 * Add a new entry to the hash table.
120
 */
Daniel Veillard's avatar
Daniel Veillard committed
121
XMLPUBFUN int XMLCALL
122
			xmlHashAddEntry	(xmlHashTablePtr table,
123
124
		                         const xmlChar *name,
		                         void *userdata);
Daniel Veillard's avatar
Daniel Veillard committed
125
XMLPUBFUN int XMLCALL
126
			xmlHashUpdateEntry(xmlHashTablePtr table,
127
128
129
		                         const xmlChar *name,
		                         void *userdata,
					 xmlHashDeallocator f);
Daniel Veillard's avatar
Daniel Veillard committed
130
XMLPUBFUN int XMLCALL
131
			xmlHashAddEntry2(xmlHashTablePtr table,
132
133
134
		                         const xmlChar *name,
		                         const xmlChar *name2,
		                         void *userdata);
Daniel Veillard's avatar
Daniel Veillard committed
135
XMLPUBFUN int XMLCALL
136
			xmlHashUpdateEntry2(xmlHashTablePtr table,
137
138
139
140
		                         const xmlChar *name,
		                         const xmlChar *name2,
		                         void *userdata,
					 xmlHashDeallocator f);
Daniel Veillard's avatar
Daniel Veillard committed
141
XMLPUBFUN int XMLCALL
142
			xmlHashAddEntry3(xmlHashTablePtr table,
143
144
145
146
		                         const xmlChar *name,
		                         const xmlChar *name2,
		                         const xmlChar *name3,
		                         void *userdata);
Daniel Veillard's avatar
Daniel Veillard committed
147
XMLPUBFUN int XMLCALL
148
			xmlHashUpdateEntry3(xmlHashTablePtr table,
149
150
151
152
153
154
155
		                         const xmlChar *name,
		                         const xmlChar *name2,
		                         const xmlChar *name3,
		                         void *userdata,
					 xmlHashDeallocator f);

/*
156
 * Remove an entry from the hash table.
157
 */
Daniel Veillard's avatar
Daniel Veillard committed
158
XMLPUBFUN int XMLCALL
159
			xmlHashRemoveEntry(xmlHashTablePtr table, const xmlChar *name,
160
                           xmlHashDeallocator f);
Daniel Veillard's avatar
Daniel Veillard committed
161
XMLPUBFUN int XMLCALL
162
			xmlHashRemoveEntry2(xmlHashTablePtr table, const xmlChar *name,
163
                            const xmlChar *name2, xmlHashDeallocator f);
Daniel Veillard's avatar
Daniel Veillard committed
164
XMLPUBFUN int  XMLCALL
165
			xmlHashRemoveEntry3(xmlHashTablePtr table, const xmlChar *name,
166
167
168
169
                            const xmlChar *name2, const xmlChar *name3,
                            xmlHashDeallocator f);

/*
170
 * Retrieve the userdata.
171
 */
Daniel Veillard's avatar
Daniel Veillard committed
172
XMLPUBFUN void * XMLCALL
173
			xmlHashLookup	(xmlHashTablePtr table,
174
					 const xmlChar *name);
Daniel Veillard's avatar
Daniel Veillard committed
175
XMLPUBFUN void * XMLCALL
176
			xmlHashLookup2	(xmlHashTablePtr table,
177
178
					 const xmlChar *name,
					 const xmlChar *name2);
Daniel Veillard's avatar
Daniel Veillard committed
179
XMLPUBFUN void * XMLCALL
180
			xmlHashLookup3	(xmlHashTablePtr table,
181
182
183
					 const xmlChar *name,
					 const xmlChar *name2,
					 const xmlChar *name3);
Daniel Veillard's avatar
Daniel Veillard committed
184
XMLPUBFUN void * XMLCALL
185
186
187
			xmlHashQLookup	(xmlHashTablePtr table,
					 const xmlChar *name,
					 const xmlChar *prefix);
Daniel Veillard's avatar
Daniel Veillard committed
188
XMLPUBFUN void * XMLCALL
189
190
191
192
193
			xmlHashQLookup2	(xmlHashTablePtr table,
					 const xmlChar *name,
					 const xmlChar *prefix,
					 const xmlChar *name2,
					 const xmlChar *prefix2);
Daniel Veillard's avatar
Daniel Veillard committed
194
XMLPUBFUN void * XMLCALL
195
196
197
198
199
200
201
			xmlHashQLookup3	(xmlHashTablePtr table,
					 const xmlChar *name,
					 const xmlChar *prefix,
					 const xmlChar *name2,
					 const xmlChar *prefix2,
					 const xmlChar *name3,
					 const xmlChar *prefix3);
202
203

/*
204
 * Helpers.
205
 */
Daniel Veillard's avatar
Daniel Veillard committed
206
XMLPUBFUN xmlHashTablePtr XMLCALL
207
			xmlHashCopy	(xmlHashTablePtr table,
208
					 xmlHashCopier f);
Daniel Veillard's avatar
Daniel Veillard committed
209
XMLPUBFUN int XMLCALL
210
			xmlHashSize	(xmlHashTablePtr table);
Daniel Veillard's avatar
Daniel Veillard committed
211
XMLPUBFUN void XMLCALL
212
			xmlHashScan	(xmlHashTablePtr table,
213
214
					 xmlHashScanner f,
					 void *data);
Daniel Veillard's avatar
Daniel Veillard committed
215
XMLPUBFUN void XMLCALL
216
			xmlHashScan3	(xmlHashTablePtr table,
217
218
219
220
221
					 const xmlChar *name,
					 const xmlChar *name2,
					 const xmlChar *name3,
					 xmlHashScanner f,
					 void *data);
Daniel Veillard's avatar
Daniel Veillard committed
222
XMLPUBFUN void XMLCALL
223
			xmlHashScanFull	(xmlHashTablePtr table,
224
225
					 xmlHashScannerFull f,
					 void *data);
Daniel Veillard's avatar
Daniel Veillard committed
226
XMLPUBFUN void XMLCALL
227
			xmlHashScanFull3(xmlHashTablePtr table,
228
229
230
231
232
					 const xmlChar *name,
					 const xmlChar *name2,
					 const xmlChar *name3,
					 xmlHashScannerFull f,
					 void *data);
233
234
235
236
#ifdef __cplusplus
}
#endif
#endif /* ! __XML_HASH_H__ */