Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1 | /* |
William M. Brack | 21e4ef2 | 2005-01-02 09:53:13 +0000 | [diff] [blame] | 2 | * Summary: Chained hash tables |
| 3 | * Description: This module implements the hash table support used in |
| 4 | * various places in the library. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 5 | * |
Daniel Veillard | be58697 | 2003-11-18 20:56:51 +0000 | [diff] [blame] | 6 | * Copy: See Copyright for the status of this software. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 7 | * |
Daniel Veillard | be58697 | 2003-11-18 20:56:51 +0000 | [diff] [blame] | 8 | * Author: Bjorn Reese <bjorn.reese@systematic.dk> |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #ifndef __XML_HASH_H__ |
| 12 | #define __XML_HASH_H__ |
| 13 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
| 18 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 19 | * The hash table. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 20 | */ |
| 21 | typedef struct _xmlHashTable xmlHashTable; |
| 22 | typedef xmlHashTable *xmlHashTablePtr; |
| 23 | |
Daniel Veillard | 5841f0e | 2003-11-20 11:59:09 +0000 | [diff] [blame] | 24 | #ifdef __cplusplus |
| 25 | } |
| 26 | #endif |
| 27 | |
| 28 | #include <libxml/xmlversion.h> |
| 29 | #include <libxml/parser.h> |
Daniel Veillard | 316a5c3 | 2005-01-23 22:56:39 +0000 | [diff] [blame] | 30 | #include <libxml/dict.h> |
Daniel Veillard | 5841f0e | 2003-11-20 11:59:09 +0000 | [diff] [blame] | 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 36 | /* |
William M. Brack | ad0e67c | 2004-12-01 14:35:10 +0000 | [diff] [blame] | 37 | * Recent version of gcc produce a warning when a function pointer is assigned |
| 38 | * to an object pointer, or vice versa. The following macro is a dirty hack |
| 39 | * to allow suppression of the warning. If your architecture has function |
| 40 | * pointers which are a different size than a void pointer, there may be some |
| 41 | * serious trouble within the library. |
| 42 | */ |
| 43 | /** |
| 44 | * XML_CAST_FPTR: |
| 45 | * @fptr: pointer to a function |
| 46 | * |
| 47 | * Macro to do a casting from an object pointer to a |
| 48 | * function pointer without encountering a warning from |
| 49 | * gcc |
| 50 | * |
Daniel Veillard | c0c6ce2 | 2005-03-10 09:22:07 +0000 | [diff] [blame] | 51 | * #define XML_CAST_FPTR(fptr) (*(void **)(&fptr)) |
| 52 | * This macro violated ISO C aliasing rules (gcc4 on s390 broke) |
| 53 | * so it is disabled now |
William M. Brack | ad0e67c | 2004-12-01 14:35:10 +0000 | [diff] [blame] | 54 | */ |
Daniel Veillard | c0c6ce2 | 2005-03-10 09:22:07 +0000 | [diff] [blame] | 55 | |
| 56 | #define XML_CAST_FPTR(fptr) fptr |
| 57 | |
William M. Brack | ad0e67c | 2004-12-01 14:35:10 +0000 | [diff] [blame] | 58 | |
| 59 | /* |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 60 | * function types: |
| 61 | */ |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 62 | /** |
| 63 | * xmlHashDeallocator: |
| 64 | * @payload: the data in the hash |
| 65 | * @name: the name associated |
| 66 | * |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 67 | * Callback to free data from a hash. |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 68 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 69 | typedef void (*xmlHashDeallocator)(void *payload, xmlChar *name); |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 70 | /** |
| 71 | * xmlHashCopier: |
| 72 | * @payload: the data in the hash |
| 73 | * @name: the name associated |
| 74 | * |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 75 | * Callback to copy data from a hash. |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 76 | * |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 77 | * Returns a copy of the data or NULL in case of error. |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 78 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 79 | typedef void *(*xmlHashCopier)(void *payload, xmlChar *name); |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 80 | /** |
| 81 | * xmlHashScanner: |
| 82 | * @payload: the data in the hash |
| 83 | * @data: extra scannner data |
| 84 | * @name: the name associated |
| 85 | * |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 86 | * Callback when scanning data in a hash with the simple scanner. |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 87 | */ |
| 88 | typedef void (*xmlHashScanner)(void *payload, void *data, xmlChar *name); |
| 89 | /** |
| 90 | * xmlHashScannerFull: |
| 91 | * @payload: the data in the hash |
| 92 | * @data: extra scannner data |
| 93 | * @name: the name associated |
| 94 | * @name2: the second name associated |
| 95 | * @name3: the third name associated |
| 96 | * |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 97 | * Callback when scanning data in a hash with the full scanner. |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 98 | */ |
Thomas Broyer | e812624 | 2001-07-22 03:54:15 +0000 | [diff] [blame] | 99 | typedef void (*xmlHashScannerFull)(void *payload, void *data, |
| 100 | const xmlChar *name, const xmlChar *name2, |
| 101 | const xmlChar *name3); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 102 | |
| 103 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 104 | * Constructor and destructor. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 105 | */ |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 106 | XMLPUBFUN xmlHashTablePtr XMLCALL |
| 107 | xmlHashCreate (int size); |
Daniel Veillard | 316a5c3 | 2005-01-23 22:56:39 +0000 | [diff] [blame] | 108 | XMLPUBFUN xmlHashTablePtr XMLCALL |
| 109 | xmlHashCreateDict(int size, |
| 110 | xmlDictPtr dict); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 111 | XMLPUBFUN void XMLCALL |
| 112 | xmlHashFree (xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 113 | xmlHashDeallocator f); |
| 114 | |
| 115 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 116 | * Add a new entry to the hash table. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 117 | */ |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 118 | XMLPUBFUN int XMLCALL |
| 119 | xmlHashAddEntry (xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 120 | const xmlChar *name, |
| 121 | void *userdata); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 122 | XMLPUBFUN int XMLCALL |
| 123 | xmlHashUpdateEntry(xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 124 | const xmlChar *name, |
| 125 | void *userdata, |
| 126 | xmlHashDeallocator f); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 127 | XMLPUBFUN int XMLCALL |
| 128 | xmlHashAddEntry2(xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 129 | const xmlChar *name, |
| 130 | const xmlChar *name2, |
| 131 | void *userdata); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 132 | XMLPUBFUN int XMLCALL |
| 133 | xmlHashUpdateEntry2(xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 134 | const xmlChar *name, |
| 135 | const xmlChar *name2, |
| 136 | void *userdata, |
| 137 | xmlHashDeallocator f); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 138 | XMLPUBFUN int XMLCALL |
| 139 | xmlHashAddEntry3(xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 140 | const xmlChar *name, |
| 141 | const xmlChar *name2, |
| 142 | const xmlChar *name3, |
| 143 | void *userdata); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 144 | XMLPUBFUN int XMLCALL |
| 145 | xmlHashUpdateEntry3(xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 146 | const xmlChar *name, |
| 147 | const xmlChar *name2, |
| 148 | const xmlChar *name3, |
| 149 | void *userdata, |
| 150 | xmlHashDeallocator f); |
| 151 | |
| 152 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 153 | * Remove an entry from the hash table. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 154 | */ |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 155 | XMLPUBFUN int XMLCALL |
| 156 | xmlHashRemoveEntry(xmlHashTablePtr table, const xmlChar *name, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 157 | xmlHashDeallocator f); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 158 | XMLPUBFUN int XMLCALL |
| 159 | xmlHashRemoveEntry2(xmlHashTablePtr table, const xmlChar *name, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 160 | const xmlChar *name2, xmlHashDeallocator f); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 161 | XMLPUBFUN int XMLCALL |
| 162 | xmlHashRemoveEntry3(xmlHashTablePtr table, const xmlChar *name, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 163 | const xmlChar *name2, const xmlChar *name3, |
| 164 | xmlHashDeallocator f); |
| 165 | |
| 166 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 167 | * Retrieve the userdata. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 168 | */ |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 169 | XMLPUBFUN void * XMLCALL |
| 170 | xmlHashLookup (xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 171 | const xmlChar *name); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 172 | XMLPUBFUN void * XMLCALL |
| 173 | xmlHashLookup2 (xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 174 | const xmlChar *name, |
| 175 | const xmlChar *name2); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 176 | XMLPUBFUN void * XMLCALL |
| 177 | xmlHashLookup3 (xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 178 | const xmlChar *name, |
| 179 | const xmlChar *name2, |
| 180 | const xmlChar *name3); |
Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 181 | XMLPUBFUN void * XMLCALL |
| 182 | xmlHashQLookup (xmlHashTablePtr table, |
| 183 | const xmlChar *name, |
| 184 | const xmlChar *prefix); |
| 185 | XMLPUBFUN void * XMLCALL |
| 186 | xmlHashQLookup2 (xmlHashTablePtr table, |
| 187 | const xmlChar *name, |
| 188 | const xmlChar *prefix, |
| 189 | const xmlChar *name2, |
| 190 | const xmlChar *prefix2); |
| 191 | XMLPUBFUN void * XMLCALL |
| 192 | xmlHashQLookup3 (xmlHashTablePtr table, |
| 193 | const xmlChar *name, |
| 194 | const xmlChar *prefix, |
| 195 | const xmlChar *name2, |
| 196 | const xmlChar *prefix2, |
| 197 | const xmlChar *name3, |
| 198 | const xmlChar *prefix3); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 199 | |
| 200 | /* |
Daniel Veillard | 61f2617 | 2002-03-12 18:46:39 +0000 | [diff] [blame] | 201 | * Helpers. |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 202 | */ |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 203 | XMLPUBFUN xmlHashTablePtr XMLCALL |
| 204 | xmlHashCopy (xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 205 | xmlHashCopier f); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 206 | XMLPUBFUN int XMLCALL |
| 207 | xmlHashSize (xmlHashTablePtr table); |
| 208 | XMLPUBFUN void XMLCALL |
| 209 | xmlHashScan (xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 210 | xmlHashScanner f, |
| 211 | void *data); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 212 | XMLPUBFUN void XMLCALL |
| 213 | xmlHashScan3 (xmlHashTablePtr table, |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 214 | const xmlChar *name, |
| 215 | const xmlChar *name2, |
| 216 | const xmlChar *name3, |
| 217 | xmlHashScanner f, |
| 218 | void *data); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 219 | XMLPUBFUN void XMLCALL |
| 220 | xmlHashScanFull (xmlHashTablePtr table, |
Thomas Broyer | e812624 | 2001-07-22 03:54:15 +0000 | [diff] [blame] | 221 | xmlHashScannerFull f, |
| 222 | void *data); |
Igor Zlatkovic | 76874e4 | 2003-08-25 09:05:12 +0000 | [diff] [blame] | 223 | XMLPUBFUN void XMLCALL |
| 224 | xmlHashScanFull3(xmlHashTablePtr table, |
Thomas Broyer | e812624 | 2001-07-22 03:54:15 +0000 | [diff] [blame] | 225 | const xmlChar *name, |
| 226 | const xmlChar *name2, |
| 227 | const xmlChar *name3, |
| 228 | xmlHashScannerFull f, |
| 229 | void *data); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 230 | #ifdef __cplusplus |
| 231 | } |
| 232 | #endif |
| 233 | #endif /* ! __XML_HASH_H__ */ |