hash.h 6.4 KB

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