1/**
2 * @file
3 *
4 * @brief Chained hash tables
5 *
6 * This module implements the hash table support used in
7 * various places in the library.
8 *
9 * @copyright See Copyright for the status of this software.
10 */
11
12#ifndef __XML_HASH_H__
13#define __XML_HASH_H__
14
15#include <libxml/xmlversion.h>
16#include <libxml/dict.h>
17#include <libxml/xmlstring.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/**
24 * Hash table mapping strings to pointers
25 *
26 * Also supports lookup using two or three strings as key.
27 */
28typedef struct _xmlHashTable xmlHashTable;
29typedef xmlHashTable *xmlHashTablePtr;
30
31/*
32 * Recent version of gcc produce a warning when a function pointer is assigned
33 * to an object pointer, or vice versa. The following macro is a dirty hack
34 * to allow suppression of the warning. If your architecture has function
35 * pointers which are a different size than a void pointer, there may be some
36 * serious trouble within the library.
37 */
38/**
39 * Macro to do a casting from an object pointer to a
40 * function pointer without encountering a warning from
41 * gcc
42 *
43 * \#define XML_CAST_FPTR(fptr) (*(void **)(&fptr))
44 * This macro violated ISO C aliasing rules (gcc4 on s390 broke)
45 * so it is disabled now
46 *
47 * @param fptr pointer to a function
48 */
49
50#define XML_CAST_FPTR(fptr) fptr
51
52/*
53 * function types:
54 */
55/**
56 * Callback to free data from a hash.
57 *
58 * @param payload the data in the hash
59 * @param name the name associated
60 */
61typedef void (*xmlHashDeallocator)(void *payload, const xmlChar *name);
62/**
63 * Callback to copy data from a hash.
64 *
65 * @param payload the data in the hash
66 * @param name the name associated
67 * @returns a copy of the data or NULL in case of error.
68 */
69typedef void *(*xmlHashCopier)(void *payload, const xmlChar *name);
70/**
71 * Callback when scanning data in a hash with the simple scanner.
72 *
73 * @param payload the data in the hash
74 * @param data extra scanner data
75 * @param name the name associated
76 */
77typedef void (*xmlHashScanner)(void *payload, void *data, const xmlChar *name);
78/**
79 * Callback when scanning data in a hash with the full scanner.
80 *
81 * @param payload the data in the hash
82 * @param data extra scanner data
83 * @param name the name associated
84 * @param name2 the second name associated
85 * @param name3 the third name associated
86 */
87typedef void (*xmlHashScannerFull)(void *payload, void *data,
88 const xmlChar *name, const xmlChar *name2,
89 const xmlChar *name3);
90
91/*
92 * Constructor and destructor.
93 */
94XMLPUBFUN xmlHashTable *
95 xmlHashCreate (int size);
96XMLPUBFUN xmlHashTable *
97 xmlHashCreateDict (int size,
98 xmlDict *dict);
99XMLPUBFUN void
100 xmlHashFree (xmlHashTable *hash,
101 xmlHashDeallocator dealloc);
102XMLPUBFUN void
103 xmlHashDefaultDeallocator(void *entry,
104 const xmlChar *name);
105
106/*
107 * Add a new entry to the hash table.
108 */
109XMLPUBFUN int
110 xmlHashAdd (xmlHashTable *hash,
111 const xmlChar *name,
112 void *userdata);
113XMLPUBFUN int
114 xmlHashAddEntry (xmlHashTable *hash,
115 const xmlChar *name,
116 void *userdata);
117XMLPUBFUN int
118 xmlHashUpdateEntry (xmlHashTable *hash,
119 const xmlChar *name,
120 void *userdata,
121 xmlHashDeallocator dealloc);
122XMLPUBFUN int
123 xmlHashAdd2 (xmlHashTable *hash,
124 const xmlChar *name,
125 const xmlChar *name2,
126 void *userdata);
127XMLPUBFUN int
128 xmlHashAddEntry2 (xmlHashTable *hash,
129 const xmlChar *name,
130 const xmlChar *name2,
131 void *userdata);
132XMLPUBFUN int
133 xmlHashUpdateEntry2 (xmlHashTable *hash,
134 const xmlChar *name,
135 const xmlChar *name2,
136 void *userdata,
137 xmlHashDeallocator dealloc);
138XMLPUBFUN int
139 xmlHashAdd3 (xmlHashTable *hash,
140 const xmlChar *name,
141 const xmlChar *name2,
142 const xmlChar *name3,
143 void *userdata);
144XMLPUBFUN int
145 xmlHashAddEntry3 (xmlHashTable *hash,
146 const xmlChar *name,
147 const xmlChar *name2,
148 const xmlChar *name3,
149 void *userdata);
150XMLPUBFUN int
151 xmlHashUpdateEntry3 (xmlHashTable *hash,
152 const xmlChar *name,
153 const xmlChar *name2,
154 const xmlChar *name3,
155 void *userdata,
156 xmlHashDeallocator dealloc);
157
158/*
159 * Remove an entry from the hash table.
160 */
161XMLPUBFUN int
162 xmlHashRemoveEntry (xmlHashTable *hash,
163 const xmlChar *name,
164 xmlHashDeallocator dealloc);
165XMLPUBFUN int
166 xmlHashRemoveEntry2 (xmlHashTable *hash,
167 const xmlChar *name,
168 const xmlChar *name2,
169 xmlHashDeallocator dealloc);
170XMLPUBFUN int
171 xmlHashRemoveEntry3 (xmlHashTable *hash,
172 const xmlChar *name,
173 const xmlChar *name2,
174 const xmlChar *name3,
175 xmlHashDeallocator dealloc);
176
177/*
178 * Retrieve the payload.
179 */
180XMLPUBFUN void *
181 xmlHashLookup (xmlHashTable *hash,
182 const xmlChar *name);
183XMLPUBFUN void *
184 xmlHashLookup2 (xmlHashTable *hash,
185 const xmlChar *name,
186 const xmlChar *name2);
187XMLPUBFUN void *
188 xmlHashLookup3 (xmlHashTable *hash,
189 const xmlChar *name,
190 const xmlChar *name2,
191 const xmlChar *name3);
192XMLPUBFUN void *
193 xmlHashQLookup (xmlHashTable *hash,
194 const xmlChar *prefix,
195 const xmlChar *name);
196XMLPUBFUN void *
197 xmlHashQLookup2 (xmlHashTable *hash,
198 const xmlChar *prefix,
199 const xmlChar *name,
200 const xmlChar *prefix2,
201 const xmlChar *name2);
202XMLPUBFUN void *
203 xmlHashQLookup3 (xmlHashTable *hash,
204 const xmlChar *prefix,
205 const xmlChar *name,
206 const xmlChar *prefix2,
207 const xmlChar *name2,
208 const xmlChar *prefix3,
209 const xmlChar *name3);
210
211/*
212 * Helpers.
213 */
214XMLPUBFUN xmlHashTable *
215 xmlHashCopySafe (xmlHashTable *hash,
216 xmlHashCopier copy,
217 xmlHashDeallocator dealloc);
218XMLPUBFUN xmlHashTable *
219 xmlHashCopy (xmlHashTable *hash,
220 xmlHashCopier copy);
221XMLPUBFUN int
222 xmlHashSize (xmlHashTable *hash);
223XMLPUBFUN void
224 xmlHashScan (xmlHashTable *hash,
225 xmlHashScanner scan,
226 void *data);
227XMLPUBFUN void
228 xmlHashScan3 (xmlHashTable *hash,
229 const xmlChar *name,
230 const xmlChar *name2,
231 const xmlChar *name3,
232 xmlHashScanner scan,
233 void *data);
234XMLPUBFUN void
235 xmlHashScanFull (xmlHashTable *hash,
236 xmlHashScannerFull scan,
237 void *data);
238XMLPUBFUN void
239 xmlHashScanFull3 (xmlHashTable *hash,
240 const xmlChar *name,
241 const xmlChar *name2,
242 const xmlChar *name3,
243 xmlHashScannerFull scan,
244 void *data);
245#ifdef __cplusplus
246}
247#endif
248#endif /* ! __XML_HASH_H__ */
249