Daniel Veillard | 3fe8768 | 2000-10-23 08:10:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * hash.c: chained hash tables |
| 3 | * |
| 4 | * Copyright (C) 2000 Bjorn Reese and Daniel Veillard. |
| 5 | * |
| 6 | * Permission to use, copy, modify, and distribute this software for any |
| 7 | * purpose with or without fee is hereby granted, provided that the above |
| 8 | * copyright notice and this permission notice appear in all copies. |
| 9 | * |
| 10 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
| 11 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 12 | * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND |
| 13 | * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. |
| 14 | * |
| 15 | * Author: bjorn.reese@systematic.dk |
| 16 | */ |
| 17 | |
| 18 | #ifndef __XML_HASH_H__ |
| 19 | #define __XML_HASH_H__ |
| 20 | |
| 21 | #include <libxml/parser.h> |
| 22 | |
| 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | |
| 27 | /* |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 28 | * The hash table |
Daniel Veillard | 3fe8768 | 2000-10-23 08:10:05 +0000 | [diff] [blame] | 29 | */ |
| 30 | typedef struct _xmlHashTable xmlHashTable; |
| 31 | typedef xmlHashTable *xmlHashTablePtr; |
Daniel Veillard | 3fe8768 | 2000-10-23 08:10:05 +0000 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * function types: |
| 35 | */ |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 36 | typedef void (*xmlHashDeallocator)(void *payload, xmlChar *name); |
| 37 | typedef void *(*xmlHashCopier)(void *payload, xmlChar *name); |
| 38 | typedef void *(*xmlHashScanner)(void *payload, void *data, xmlChar *name); |
Daniel Veillard | 3fe8768 | 2000-10-23 08:10:05 +0000 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * Constructor and destructor |
| 42 | */ |
| 43 | xmlHashTablePtr xmlHashCreate (int size); |
| 44 | void xmlHashFree (xmlHashTablePtr table, |
| 45 | xmlHashDeallocator f); |
| 46 | |
| 47 | /* |
| 48 | * Add a new entry to the hash table |
| 49 | */ |
| 50 | int xmlHashAddEntry (xmlHashTablePtr table, |
| 51 | const xmlChar *name, |
| 52 | void *userdata); |
| 53 | int xmlHashUpdateEntry(xmlHashTablePtr table, |
| 54 | const xmlChar *name, |
| 55 | void *userdata, |
| 56 | xmlHashDeallocator f); |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 57 | int xmlHashAddEntry2(xmlHashTablePtr table, |
| 58 | const xmlChar *name, |
| 59 | const xmlChar *name2, |
| 60 | void *userdata); |
| 61 | int xmlHashUpdateEntry2(xmlHashTablePtr table, |
| 62 | const xmlChar *name, |
| 63 | const xmlChar *name2, |
| 64 | void *userdata, |
| 65 | xmlHashDeallocator f); |
| 66 | int xmlHashAddEntry3(xmlHashTablePtr table, |
| 67 | const xmlChar *name, |
| 68 | const xmlChar *name2, |
| 69 | const xmlChar *name3, |
| 70 | void *userdata); |
| 71 | int xmlHashUpdateEntry3(xmlHashTablePtr table, |
| 72 | const xmlChar *name, |
| 73 | const xmlChar *name2, |
| 74 | const xmlChar *name3, |
| 75 | void *userdata, |
| 76 | xmlHashDeallocator f); |
Daniel Veillard | d194dd2 | 2001-02-14 10:37:43 +0000 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Remove an entry from the hash table |
| 80 | */ |
| 81 | int xmlHashRemoveEntry(xmlHashTablePtr table, const xmlChar *name, |
| 82 | xmlHashDeallocator f); |
| 83 | int xmlHashRemoveEntry2(xmlHashTablePtr table, const xmlChar *name, |
| 84 | const xmlChar *name2, xmlHashDeallocator f); |
| 85 | int xmlHashRemoveEntry3(xmlHashTablePtr table, const xmlChar *name, |
| 86 | const xmlChar *name2, const xmlChar *name3, |
| 87 | xmlHashDeallocator f); |
| 88 | |
Daniel Veillard | 3fe8768 | 2000-10-23 08:10:05 +0000 | [diff] [blame] | 89 | /* |
| 90 | * Retrieve the userdata |
| 91 | */ |
| 92 | void * xmlHashLookup (xmlHashTablePtr table, |
| 93 | const xmlChar *name); |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 94 | void * xmlHashLookup2 (xmlHashTablePtr table, |
| 95 | const xmlChar *name, |
| 96 | const xmlChar *name2); |
| 97 | void * xmlHashLookup3 (xmlHashTablePtr table, |
| 98 | const xmlChar *name, |
| 99 | const xmlChar *name2, |
| 100 | const xmlChar *name3); |
Daniel Veillard | 3fe8768 | 2000-10-23 08:10:05 +0000 | [diff] [blame] | 101 | |
| 102 | /* |
| 103 | * Helpers |
| 104 | */ |
| 105 | xmlHashTablePtr xmlHashCopy (xmlHashTablePtr table, |
| 106 | xmlHashCopier f); |
Daniel Veillard | 1f83d39 | 2001-02-08 09:37:42 +0000 | [diff] [blame] | 107 | int xmlHashSize (xmlHashTablePtr); |
Daniel Veillard | 3fe8768 | 2000-10-23 08:10:05 +0000 | [diff] [blame] | 108 | void xmlHashScan (xmlHashTablePtr table, |
| 109 | xmlHashScanner f, |
| 110 | void *data); |
Daniel Veillard | 126f279 | 2000-10-24 17:10:12 +0000 | [diff] [blame] | 111 | void xmlHashScan1 (xmlHashTablePtr table, |
| 112 | const xmlChar *name, |
| 113 | xmlHashScanner f, |
| 114 | void *data); |
| 115 | void xmlHashScan2 (xmlHashTablePtr table, |
| 116 | const xmlChar *name, |
| 117 | const xmlChar *name2, |
| 118 | xmlHashScanner f, |
| 119 | void *data); |
| 120 | void xmlHashScan3 (xmlHashTablePtr table, |
| 121 | const xmlChar *name, |
| 122 | const xmlChar *name2, |
| 123 | const xmlChar *name3, |
| 124 | xmlHashScanner f, |
| 125 | void *data); |
Daniel Veillard | 3fe8768 | 2000-10-23 08:10:05 +0000 | [diff] [blame] | 126 | #ifdef __cplusplus |
| 127 | } |
| 128 | #endif |
| 129 | #endif /* ! __XML_HASH_H__ */ |