hash.h 6.9 KB

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