hash.c revision 38ae7e4efe803ea78b6499cd05a394db32623e41
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * hash.c: chained hash tables
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Reference: Your favorite introductory book on algorithms
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Copyright (C) 2000 Bjorn Reese and Daniel Veillard.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Permission to use, copy, modify, and distribute this software for any
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * purpose with or without fee is hereby granted, provided that the above
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * copyright notice and this permission notice appear in all copies.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Author: breese@users.sourceforge.net
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync/* #define DEBUG_GROW */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * A single entry in the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * The entire hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashComputeKey:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Calculate the hash key
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncstatic unsigned long
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashComputeKey(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync unsigned long value = 0L;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncstatic unsigned long
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync unsigned long value = 0L;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)':');
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)':');
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)':');
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashCreate:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @size: the size of the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Create a new xmlHashTablePtr.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns the newly created object, or NULL if an error occured.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync table->table = xmlMalloc(size * sizeof(xmlHashEntry));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync memset(table->table, 0, size * sizeof(xmlHashEntry));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashCreateDict:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @size: the size of the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @dict: a dictionary to use for the hash
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Create a new xmlHashTablePtr which will use @dict as the internal dictionary
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns the newly created object, or NULL if an error occured.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashGrow:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @size: the new size of the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * resize the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns 0 in case of success, -1 in case of failure
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync unsigned long key;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync unsigned long nbElem = 0;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync table->table = xmlMalloc(size * sizeof(xmlHashEntry));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync memset(table->table, 0, size * sizeof(xmlHashEntry));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync /* If the two loops are merged, there would be situations where
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync a new entry needs to allocated and data copied into it from
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync the main table. So instead, we run through the array twice, first
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync copying all the elements in the main array (where we can't get
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync conflicts) and then the rest, so we only free (and don't allocate)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (i = 0; i < oldsize; i++) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync key = xmlHashComputeKey(table, oldtable[i].name, oldtable[i].name2,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync memcpy(&(table->table[key]), &(oldtable[i]), sizeof(xmlHashEntry));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (i = 0; i < oldsize; i++) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * put back the entry in the new table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync key = xmlHashComputeKey(table, iter->name, iter->name2,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync memcpy(&(table->table[key]), iter, sizeof(xmlHashEntry));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync "xmlHashGrow : from %d to %d, %d elems\n", oldsize, size, nbElem);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashFree:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the deallocator function for items in the hash
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Free the hash @table and its contents. The userdata is
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * deallocated with @f if provided.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashFree(xmlHashTablePtr table, xmlHashDeallocator f) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for(i = 0; (i < table->size) && (nbElems > 0); i++) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashAddEntry:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @userdata: a pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Add the @userdata to the hash @table. This can later be retrieved
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * by using the @name. Duplicate names generate errors.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns 0 the addition succeeded and -1 in case of error.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashAddEntry(xmlHashTablePtr table, const xmlChar *name, void *userdata) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(xmlHashAddEntry3(table, name, NULL, NULL, userdata));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashAddEntry2:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @userdata: a pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Add the @userdata to the hash @table. This can later be retrieved
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * by using the (@name, @name2) tuple. Duplicate tuples generate errors.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns 0 the addition succeeded and -1 in case of error.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashAddEntry2(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(xmlHashAddEntry3(table, name, name2, NULL, userdata));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashUpdateEntry:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @userdata: a pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the deallocator function for replaced item (if any)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Add the @userdata to the hash @table. This can later be retrieved
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * by using the @name. Existing entry for this @name will be removed
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * and freed with @f if found.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns 0 the addition succeeded and -1 in case of error.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashUpdateEntry(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(xmlHashUpdateEntry3(table, name, NULL, NULL, userdata, f));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashUpdateEntry2:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @userdata: a pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the deallocator function for replaced item (if any)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Add the @userdata to the hash @table. This can later be retrieved
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * by using the (@name, @name2) tuple. Existing entry for this tuple will
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * be removed and freed with @f if found.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns 0 the addition succeeded and -1 in case of error.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashUpdateEntry2(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(xmlHashUpdateEntry3(table, name, name2, NULL, userdata, f));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashLookup:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Find the userdata specified by the @name.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns the pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashLookup(xmlHashTablePtr table, const xmlChar *name) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashLookup2:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Find the userdata specified by the (@name, @name2) tuple.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns the pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashLookup2(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashQLookup:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @prefix: the prefix of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Find the userdata specified by the QName @prefix:@name/@name.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns the pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashQLookup(xmlHashTablePtr table, const xmlChar *prefix,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(xmlHashQLookup3(table, prefix, name, NULL, NULL, NULL, NULL));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashQLookup2:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @prefix: the prefix of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @prefix2: the second prefix of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Find the userdata specified by the QNames tuple
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns the pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashQLookup2(xmlHashTablePtr table, const xmlChar *prefix,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(xmlHashQLookup3(table, prefix, name, prefix2, name2, NULL, NULL));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashAddEntry3:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name3: a third name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @userdata: a pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Add the @userdata to the hash @table. This can later be retrieved
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * by using the tuple (@name, @name2, @name3). Duplicate entries generate
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns 0 the addition succeeded and -1 in case of error.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashAddEntry3(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * If using a dict internalize if needed
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if ((name2 != NULL) && (!xmlDictOwns(table->dict, name2))) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if ((name3 != NULL) && (!xmlDictOwns(table->dict, name3))) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Check for duplicate and insertion location.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync key = xmlHashComputeKey(table, name, name2, name3);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (insert = &(table->table[key]); insert->next != NULL;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (insert = &(table->table[key]); insert->next != NULL;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashUpdateEntry3:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name3: a third name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @userdata: a pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the deallocator function for replaced item (if any)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Add the @userdata to the hash @table. This can later be retrieved
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * by using the tuple (@name, @name2, @name3). Existing entry for this tuple
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * will be removed and freed with @f if found.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns 0 the addition succeeded and -1 in case of error.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashUpdateEntry3(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync unsigned long key;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * If using a dict internalize if needed
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if ((name2 != NULL) && (!xmlDictOwns(table->dict, name2))) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if ((name3 != NULL) && (!xmlDictOwns(table->dict, name3))) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Check for duplicate and insertion location.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync key = xmlHashComputeKey(table, name, name2, name3);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (insert = &(table->table[key]); insert->next != NULL;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (insert = &(table->table[key]); insert->next != NULL;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashLookup3:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name3: a third name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Find the userdata specified by the (@name, @name2, @name3) tuple.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns the a pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashLookup3(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync unsigned long key;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync key = xmlHashComputeKey(table, name, name2, name3);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (entry = &(table->table[key]); entry != NULL; entry = entry->next) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (entry = &(table->table[key]); entry != NULL; entry = entry->next) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashQLookup3:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @prefix: the prefix of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @prefix2: the second prefix of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @prefix3: the third prefix of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name3: a third name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Find the userdata specified by the (@name, @name2, @name3) tuple.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns the a pointer to the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync unsigned long key;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync key = xmlHashComputeQKey(table, prefix, name, prefix2,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (entry = &(table->table[key]); entry != NULL; entry = entry->next) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsynctypedef struct {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncstubHashScannerFull (void *payload, void *data, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync stubdata->hashscanner (payload, stubdata->data, (xmlChar *) name);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashScan:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the scanner function for items in the hash
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @data: extra data passed to f
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Scan the hash @table and applied @f to each value.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashScan(xmlHashTablePtr table, xmlHashScanner f, void *data) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync xmlHashScanFull (table, stubHashScannerFull, &stubdata);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashScanFull:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the scanner function for items in the hash
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @data: extra data passed to f
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Scan the hash @table and applied @f to each value.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashScanFull(xmlHashTablePtr table, xmlHashScannerFull f, void *data) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync /* table was modified by the callback, be careful */
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashScan3:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata or NULL
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata or NULL
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name3: a third name of the userdata or NULL
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the scanner function for items in the hash
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @data: extra data passed to f
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Scan the hash @table and applied @f to each value matching
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * (@name, @name2, @name3) tuple. If one of the names is null,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * the comparison is considered to match.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashScan3(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashScanFull3:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata or NULL
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata or NULL
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name3: a third name of the userdata or NULL
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the scanner function for items in the hash
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @data: extra data passed to f
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Scan the hash @table and applied @f to each value matching
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * (@name, @name2, @name3) tuple. If one of the names is null,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * the comparison is considered to match.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashScanFull3(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync if (((name == NULL) || (xmlStrEqual(name, iter->name))) &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync ((name2 == NULL) || (xmlStrEqual(name2, iter->name2))) &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync ((name3 == NULL) || (xmlStrEqual(name3, iter->name3))) &&
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashCopy:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the copier function for items in the hash
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Scan the hash @table and applied @f to each value.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns the new table or NULL in case of error.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashCopy(xmlHashTablePtr table, xmlHashCopier f) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashSize:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Query the number of elements installed in the hash @table.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns the number of elements in the hash table or
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * -1 in case of error
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashRemoveEntry:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the deallocator function for removed item (if any)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Find the userdata specified by the @name and remove
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * it from the hash @table. Existing userdata for this tuple will be removed
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * and freed with @f.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns 0 if the removal succeeded and -1 in case of error or not found.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncint xmlHashRemoveEntry(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(xmlHashRemoveEntry3(table, name, NULL, NULL, f));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashRemoveEntry2:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the deallocator function for removed item (if any)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Find the userdata specified by the (@name, @name2) tuple and remove
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * it from the hash @table. Existing userdata for this tuple will be removed
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * and freed with @f.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns 0 if the removal succeeded and -1 in case of error or not found.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashRemoveEntry2(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(xmlHashRemoveEntry3(table, name, name2, NULL, f));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * xmlHashRemoveEntry3:
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @table: the hash table
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name: the name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name2: a second name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @name3: a third name of the userdata
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * @f: the deallocator function for removed item (if any)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Find the userdata specified by the (@name, @name2, @name3) tuple and remove
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * it from the hash @table. Existing userdata for this tuple will be removed
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * and freed with @f.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync * Returns 0 if the removal succeeded and -1 in case of error or not found.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncxmlHashRemoveEntry3(xmlHashTablePtr table, const xmlChar *name,
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync const xmlChar *name2, const xmlChar *name3, xmlHashDeallocator f) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync unsigned long key;
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync key = xmlHashComputeKey(table, name, name2, name3);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync for (entry = &(table->table[key]); entry != NULL; entry = entry->next) {
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync memcpy(&(table->table[key]), entry, sizeof(xmlHashEntry));
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync return(-1);