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