1ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/* 2ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * hash.c: chained hash tables 3ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 4ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Reference: Your favorite introductory book on algorithms 5ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 6ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Copyright (C) 2000 Bjorn Reese and Daniel Veillard. 7ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 8ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Permission to use, copy, modify, and distribute this software for any 9ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * purpose with or without fee is hereby granted, provided that the above 10ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * copyright notice and this permission notice appear in all copies. 11ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 12ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 13ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 14ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND 15ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. 16ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 17ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Author: breese@users.sourceforge.net 18ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 19ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 20ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#define IN_LIBXML 21ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#include "libxml.h" 22ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 23ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#include <string.h> 24ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#include <libxml/parser.h> 25ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#include <libxml/hash.h> 26ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#include <libxml/xmlmemory.h> 27ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#include <libxml/xmlerror.h> 28ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#include <libxml/globals.h> 29ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 30ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#define MAX_HASH_LEN 8 31ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 32ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/* #define DEBUG_GROW */ 33ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 34ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/* 35ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * A single entry in the hash table 36ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 37ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projecttypedef struct _xmlHashEntry xmlHashEntry; 38ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projecttypedef xmlHashEntry *xmlHashEntryPtr; 39ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectstruct _xmlHashEntry { 40ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project struct _xmlHashEntry *next; 41ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlChar *name; 42ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlChar *name2; 43ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlChar *name3; 44ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project void *payload; 45ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project int valid; 46ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project}; 47ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 48ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/* 49ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * The entire hash table 50ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 51ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectstruct _xmlHashTable { 52ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project struct _xmlHashEntry *table; 53ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project int size; 54ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project int nbElems; 55ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlDictPtr dict; 56ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project}; 57ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 58ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/* 59ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashComputeKey: 60ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Calculate the hash key 61ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 62ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectstatic unsigned long 63ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashComputeKey(xmlHashTablePtr table, const xmlChar *name, 64ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2, const xmlChar *name3) { 65ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project unsigned long value = 0L; 66ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project char ch; 67ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 68ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name != NULL) { 69ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value += 30 * (*name); 70ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while ((ch = *name++) != 0) { 71ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch); 72ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 73ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 74ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name2 != NULL) { 75ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while ((ch = *name2++) != 0) { 76ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch); 77ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 78ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 79ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name3 != NULL) { 80ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while ((ch = *name3++) != 0) { 81ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch); 82ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 83ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 84ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return (value % table->size); 85ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 86ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 87ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectstatic unsigned long 88ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashComputeQKey(xmlHashTablePtr table, 89ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *prefix, const xmlChar *name, 90ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *prefix2, const xmlChar *name2, 91ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *prefix3, const xmlChar *name3) { 92ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project unsigned long value = 0L; 93ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project char ch; 94ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 95ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (prefix != NULL) 96ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value += 30 * (*prefix); 97ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project else 98ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value += 30 * (*name); 99ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 100ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (prefix != NULL) { 101ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while ((ch = *prefix++) != 0) { 102ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch); 103ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 104ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)':'); 105ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 106ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name != NULL) { 107ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while ((ch = *name++) != 0) { 108ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch); 109ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 110ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 111ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (prefix2 != NULL) { 112ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while ((ch = *prefix2++) != 0) { 113ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch); 114ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 115ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)':'); 116ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 117ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name2 != NULL) { 118ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while ((ch = *name2++) != 0) { 119ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch); 120ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 121ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 122ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (prefix3 != NULL) { 123ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while ((ch = *prefix3++) != 0) { 124ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch); 125ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 126ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)':'); 127ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 128ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name3 != NULL) { 129ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while ((ch = *name3++) != 0) { 130ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project value = value ^ ((value << 5) + (value >> 3) + (unsigned long)ch); 131ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 132ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 133ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return (value % table->size); 134ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 135ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 136ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 137ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashCreate: 138ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @size: the size of the hash table 139ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 140ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Create a new xmlHashTablePtr. 141ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 142ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns the newly created object, or NULL if an error occured. 143ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 144ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashTablePtr 145ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashCreate(int size) { 146ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashTablePtr table; 147ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 148ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (size <= 0) 149ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project size = 256; 150ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 151ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table = xmlMalloc(sizeof(xmlHashTable)); 152ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table) { 153ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->dict = NULL; 154ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->size = size; 155ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->nbElems = 0; 156ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->table = xmlMalloc(size * sizeof(xmlHashEntry)); 157ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table) { 158ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project memset(table->table, 0, size * sizeof(xmlHashEntry)); 159ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(table); 160ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 161ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(table); 162ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 163ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 164ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 165ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 166ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 167ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashCreateDict: 168ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @size: the size of the hash table 169ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @dict: a dictionary to use for the hash 170ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 171ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Create a new xmlHashTablePtr which will use @dict as the internal dictionary 172ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 173ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns the newly created object, or NULL if an error occured. 174ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 175ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashTablePtr 176ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashCreateDict(int size, xmlDictPtr dict) { 177ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashTablePtr table; 178ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 179ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table = xmlHashCreate(size); 180ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table != NULL) { 181ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->dict = dict; 182ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlDictReference(dict); 183ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 184ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(table); 185ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 186ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 187ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 188ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashGrow: 189ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 190ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @size: the new size of the hash table 191ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 192ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * resize the hash table 193ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 194ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns 0 in case of success, -1 in case of failure 195ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 196ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectstatic int 197ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashGrow(xmlHashTablePtr table, int size) { 198ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project unsigned long key; 199ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project int oldsize, i; 200ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr iter, next; 201ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project struct _xmlHashEntry *oldtable; 202ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#ifdef DEBUG_GROW 203ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project unsigned long nbElem = 0; 204ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#endif 205ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 206ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table == NULL) 207ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 208ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (size < 8) 209ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 210ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (size > 8 * 2048) 211ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 212ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 213ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project oldsize = table->size; 214ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project oldtable = table->table; 215ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (oldtable == NULL) 216ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 217ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 218ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->table = xmlMalloc(size * sizeof(xmlHashEntry)); 219ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table == NULL) { 220ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->table = oldtable; 221ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 222ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 223ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project memset(table->table, 0, size * sizeof(xmlHashEntry)); 224ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->size = size; 225ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 226ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project /* If the two loops are merged, there would be situations where 227ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project a new entry needs to allocated and data copied into it from 228ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project the main table. So instead, we run through the array twice, first 229ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project copying all the elements in the main array (where we can't get 230ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project conflicts) and then the rest, so we only free (and don't allocate) 231ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 232ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for (i = 0; i < oldsize; i++) { 233ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (oldtable[i].valid == 0) 234ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project continue; 235ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project key = xmlHashComputeKey(table, oldtable[i].name, oldtable[i].name2, 236ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project oldtable[i].name3); 237ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project memcpy(&(table->table[key]), &(oldtable[i]), sizeof(xmlHashEntry)); 238ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->table[key].next = NULL; 239ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 240ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 241ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for (i = 0; i < oldsize; i++) { 242ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = oldtable[i].next; 243ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while (iter) { 244ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project next = iter->next; 245ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 246ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project /* 247ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * put back the entry in the new table 248ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 249ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 250ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project key = xmlHashComputeKey(table, iter->name, iter->name2, 251ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter->name3); 252ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[key].valid == 0) { 253ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project memcpy(&(table->table[key]), iter, sizeof(xmlHashEntry)); 254ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->table[key].next = NULL; 255ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(iter); 256ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 257ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter->next = table->table[key].next; 258ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->table[key].next = iter; 259ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 260ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 261ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#ifdef DEBUG_GROW 262ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project nbElem++; 263ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#endif 264ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 265ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = next; 266ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 267ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 268ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 269ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(oldtable); 270ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 271ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#ifdef DEBUG_GROW 272ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlGenericError(xmlGenericErrorContext, 273ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project "xmlHashGrow : from %d to %d, %d elems\n", oldsize, size, nbElem); 274ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#endif 275ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 276ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(0); 277ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 278ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 279ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 280ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashFree: 281ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 282ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the deallocator function for items in the hash 283ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 284ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Free the hash @table and its contents. The userdata is 285ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * deallocated with @f if provided. 286ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 287ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid 288ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashFree(xmlHashTablePtr table, xmlHashDeallocator f) { 289ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project int i; 290ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr iter; 291ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr next; 292ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project int inside_table = 0; 293ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project int nbElems; 294ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 295ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table == NULL) 296ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return; 297ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table) { 298ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project nbElems = table->nbElems; 299ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for(i = 0; (i < table->size) && (nbElems > 0); i++) { 300ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = &(table->table[i]); 301ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (iter->valid == 0) 302ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project continue; 303ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project inside_table = 1; 304ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while (iter) { 305ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project next = iter->next; 306ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((f != NULL) && (iter->payload != NULL)) 307ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project f(iter->payload, iter->name); 308ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->dict == NULL) { 309ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (iter->name) 310ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(iter->name); 311ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (iter->name2) 312ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(iter->name2); 313ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (iter->name3) 314ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(iter->name3); 315ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 316ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter->payload = NULL; 317ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (!inside_table) 318ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(iter); 319ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project nbElems--; 320ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project inside_table = 0; 321ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = next; 322ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 323ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project inside_table = 0; 324ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 325ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(table->table); 326ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 327ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->dict) 328ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlDictFree(table->dict); 329ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(table); 330ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 331ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 332ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 333ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashAddEntry: 334ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 335ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 336ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @userdata: a pointer to the userdata 337ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 338ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Add the @userdata to the hash @table. This can later be retrieved 339ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * by using the @name. Duplicate names generate errors. 340ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 341ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns 0 the addition succeeded and -1 in case of error. 342ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 343ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectint 344ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashAddEntry(xmlHashTablePtr table, const xmlChar *name, void *userdata) { 345ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(xmlHashAddEntry3(table, name, NULL, NULL, userdata)); 346ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 347ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 348ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 349ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashAddEntry2: 350ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 351ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 352ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata 353ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @userdata: a pointer to the userdata 354ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 355ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Add the @userdata to the hash @table. This can later be retrieved 356ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * by using the (@name, @name2) tuple. Duplicate tuples generate errors. 357ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 358ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns 0 the addition succeeded and -1 in case of error. 359ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 360ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectint 361ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashAddEntry2(xmlHashTablePtr table, const xmlChar *name, 362ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2, void *userdata) { 363ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(xmlHashAddEntry3(table, name, name2, NULL, userdata)); 364ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 365ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 366ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 367ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashUpdateEntry: 368ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 369ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 370ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @userdata: a pointer to the userdata 371ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the deallocator function for replaced item (if any) 372ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 373ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Add the @userdata to the hash @table. This can later be retrieved 374ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * by using the @name. Existing entry for this @name will be removed 375ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * and freed with @f if found. 376ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 377ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns 0 the addition succeeded and -1 in case of error. 378ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 379ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectint 380ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashUpdateEntry(xmlHashTablePtr table, const xmlChar *name, 381ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project void *userdata, xmlHashDeallocator f) { 382ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(xmlHashUpdateEntry3(table, name, NULL, NULL, userdata, f)); 383ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 384ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 385ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 386ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashUpdateEntry2: 387ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 388ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 389ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata 390ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @userdata: a pointer to the userdata 391ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the deallocator function for replaced item (if any) 392ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 393ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Add the @userdata to the hash @table. This can later be retrieved 394ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * by using the (@name, @name2) tuple. Existing entry for this tuple will 395ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * be removed and freed with @f if found. 396ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 397ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns 0 the addition succeeded and -1 in case of error. 398ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 399ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectint 400ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashUpdateEntry2(xmlHashTablePtr table, const xmlChar *name, 401ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2, void *userdata, 402ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashDeallocator f) { 403ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(xmlHashUpdateEntry3(table, name, name2, NULL, userdata, f)); 404ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 405ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 406ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 407ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashLookup: 408ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 409ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 410ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 411ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Find the userdata specified by the @name. 412ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 413ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns the pointer to the userdata 414ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 415ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid * 416ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashLookup(xmlHashTablePtr table, const xmlChar *name) { 417ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(xmlHashLookup3(table, name, NULL, NULL)); 418ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 419ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 420ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 421ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashLookup2: 422ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 423ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 424ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata 425ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 426ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Find the userdata specified by the (@name, @name2) tuple. 427ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 428ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns the pointer to the userdata 429ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 430ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid * 431ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashLookup2(xmlHashTablePtr table, const xmlChar *name, 432ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2) { 433ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(xmlHashLookup3(table, name, name2, NULL)); 434ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 435ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 436ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 437ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashQLookup: 438ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 439ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @prefix: the prefix of the userdata 440ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 441ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 442ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Find the userdata specified by the QName @prefix:@name/@name. 443ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 444ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns the pointer to the userdata 445ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 446ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid * 447ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashQLookup(xmlHashTablePtr table, const xmlChar *prefix, 448ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name) { 449ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(xmlHashQLookup3(table, prefix, name, NULL, NULL, NULL, NULL)); 450ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 451ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 452ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 453ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashQLookup2: 454ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 455ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @prefix: the prefix of the userdata 456ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 457ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @prefix2: the second prefix of the userdata 458ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata 459ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 460ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Find the userdata specified by the QNames tuple 461ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 462ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns the pointer to the userdata 463ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 464ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid * 465ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashQLookup2(xmlHashTablePtr table, const xmlChar *prefix, 466ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name, const xmlChar *prefix2, 467ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2) { 468ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(xmlHashQLookup3(table, prefix, name, prefix2, name2, NULL, NULL)); 469ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 470ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 471ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 472ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashAddEntry3: 473ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 474ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 475ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata 476ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name3: a third name of the userdata 477ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @userdata: a pointer to the userdata 478ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 479ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Add the @userdata to the hash @table. This can later be retrieved 480ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * by using the tuple (@name, @name2, @name3). Duplicate entries generate 481ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * errors. 482ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 483ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns 0 the addition succeeded and -1 in case of error. 484ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 485ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectint 486ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashAddEntry3(xmlHashTablePtr table, const xmlChar *name, 487ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2, const xmlChar *name3, 488ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project void *userdata) { 489ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project unsigned long key, len = 0; 490ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr entry; 491ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr insert; 492ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 493ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((table == NULL) || (name == NULL)) 494ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 495ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 496ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project /* 497ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * If using a dict internalize if needed 498ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 499ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->dict) { 500ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (!xmlDictOwns(table->dict, name)) { 501ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project name = xmlDictLookup(table->dict, name, -1); 502ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name == NULL) 503ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 504ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 505ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((name2 != NULL) && (!xmlDictOwns(table->dict, name2))) { 506ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project name2 = xmlDictLookup(table->dict, name2, -1); 507ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name2 == NULL) 508ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 509ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 510ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((name3 != NULL) && (!xmlDictOwns(table->dict, name3))) { 511ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project name3 = xmlDictLookup(table->dict, name3, -1); 512ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name3 == NULL) 513ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 514ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 515ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 516ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 517ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project /* 518ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Check for duplicate and insertion location. 519ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 520ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project key = xmlHashComputeKey(table, name, name2, name3); 521ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[key].valid == 0) { 522ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert = NULL; 523ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 524ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->dict) { 525ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for (insert = &(table->table[key]); insert->next != NULL; 526ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert = insert->next) { 527ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((insert->name == name) && 528ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (insert->name2 == name2) && 529ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (insert->name3 == name3)) 530ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 531ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project len++; 532ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 533ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((insert->name == name) && 534ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (insert->name2 == name2) && 535ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (insert->name3 == name3)) 536ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 537ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 538ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for (insert = &(table->table[key]); insert->next != NULL; 539ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert = insert->next) { 540ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((xmlStrEqual(insert->name, name)) && 541ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrEqual(insert->name2, name2)) && 542ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrEqual(insert->name3, name3))) 543ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 544ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project len++; 545ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 546ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((xmlStrEqual(insert->name, name)) && 547ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrEqual(insert->name2, name2)) && 548ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrEqual(insert->name3, name3))) 549ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 550ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 551ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 552ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 553ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (insert == NULL) { 554ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry = &(table->table[key]); 555ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 556ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry = xmlMalloc(sizeof(xmlHashEntry)); 557ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (entry == NULL) 558ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 559ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 560ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 561ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->dict != NULL) { 562ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name = (xmlChar *) name; 563ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name2 = (xmlChar *) name2; 564ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name3 = (xmlChar *) name3; 565ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 566ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name = xmlStrdup(name); 567ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name2 = xmlStrdup(name2); 568ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name3 = xmlStrdup(name3); 569ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 570ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->payload = userdata; 571ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->next = NULL; 572ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->valid = 1; 573ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 574ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 575ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (insert != NULL) 576ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert->next = entry; 577ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 578ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->nbElems++; 579ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 580ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (len > MAX_HASH_LEN) 581ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashGrow(table, MAX_HASH_LEN * table->size); 582ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 583ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(0); 584ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 585ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 586ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 587ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashUpdateEntry3: 588ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 589ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 590ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata 591ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name3: a third name of the userdata 592ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @userdata: a pointer to the userdata 593ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the deallocator function for replaced item (if any) 594ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 595ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Add the @userdata to the hash @table. This can later be retrieved 596ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * by using the tuple (@name, @name2, @name3). Existing entry for this tuple 597ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * will be removed and freed with @f if found. 598ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 599ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns 0 the addition succeeded and -1 in case of error. 600ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 601ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectint 602ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashUpdateEntry3(xmlHashTablePtr table, const xmlChar *name, 603ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2, const xmlChar *name3, 604ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project void *userdata, xmlHashDeallocator f) { 605ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project unsigned long key; 606ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr entry; 607ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr insert; 608ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 609ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((table == NULL) || name == NULL) 610ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 611ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 612ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project /* 613ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * If using a dict internalize if needed 614ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 615ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->dict) { 616ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (!xmlDictOwns(table->dict, name)) { 617ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project name = xmlDictLookup(table->dict, name, -1); 618ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name == NULL) 619ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 620ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 621ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((name2 != NULL) && (!xmlDictOwns(table->dict, name2))) { 622ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project name2 = xmlDictLookup(table->dict, name2, -1); 623ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name2 == NULL) 624ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 625ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 626ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((name3 != NULL) && (!xmlDictOwns(table->dict, name3))) { 627ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project name3 = xmlDictLookup(table->dict, name3, -1); 628ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name3 == NULL) 629ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 630ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 631ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 632ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 633ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project /* 634ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Check for duplicate and insertion location. 635ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 636ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project key = xmlHashComputeKey(table, name, name2, name3); 637ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[key].valid == 0) { 638ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert = NULL; 639ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 640ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table ->dict) { 641ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for (insert = &(table->table[key]); insert->next != NULL; 642ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert = insert->next) { 643ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((insert->name == name) && 644ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (insert->name2 == name2) && 645ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (insert->name3 == name3)) { 646ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (f) 647ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project f(insert->payload, insert->name); 648ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert->payload = userdata; 649ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(0); 650ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 651ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 652ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((insert->name == name) && 653ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (insert->name2 == name2) && 654ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (insert->name3 == name3)) { 655ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (f) 656ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project f(insert->payload, insert->name); 657ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert->payload = userdata; 658ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(0); 659ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 660ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 661ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for (insert = &(table->table[key]); insert->next != NULL; 662ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert = insert->next) { 663ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((xmlStrEqual(insert->name, name)) && 664ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrEqual(insert->name2, name2)) && 665ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrEqual(insert->name3, name3))) { 666ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (f) 667ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project f(insert->payload, insert->name); 668ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert->payload = userdata; 669ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(0); 670ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 671ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 672ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((xmlStrEqual(insert->name, name)) && 673ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrEqual(insert->name2, name2)) && 674ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrEqual(insert->name3, name3))) { 675ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (f) 676ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project f(insert->payload, insert->name); 677ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert->payload = userdata; 678ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(0); 679ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 680ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 681ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 682ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 683ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (insert == NULL) { 684ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry = &(table->table[key]); 685ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 686ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry = xmlMalloc(sizeof(xmlHashEntry)); 687ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (entry == NULL) 688ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 689ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 690ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 691ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->dict != NULL) { 692ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name = (xmlChar *) name; 693ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name2 = (xmlChar *) name2; 694ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name3 = (xmlChar *) name3; 695ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 696ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name = xmlStrdup(name); 697ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name2 = xmlStrdup(name2); 698ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->name3 = xmlStrdup(name3); 699ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 700ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->payload = userdata; 701ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->next = NULL; 702ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->valid = 1; 703ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->nbElems++; 704ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 705ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 706ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (insert != NULL) { 707ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project insert->next = entry; 708ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 709ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(0); 710ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 711ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 712ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 713ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashLookup3: 714ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 715ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 716ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata 717ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name3: a third name of the userdata 718ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 719ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Find the userdata specified by the (@name, @name2, @name3) tuple. 720ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 721ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns the a pointer to the userdata 722ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 723ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid * 724ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashLookup3(xmlHashTablePtr table, const xmlChar *name, 725ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2, const xmlChar *name3) { 726ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project unsigned long key; 727ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr entry; 728ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 729ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table == NULL) 730ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 731ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name == NULL) 732ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 733ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project key = xmlHashComputeKey(table, name, name2, name3); 734ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[key].valid == 0) 735ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 736ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->dict) { 737ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for (entry = &(table->table[key]); entry != NULL; entry = entry->next) { 738ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((entry->name == name) && 739ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (entry->name2 == name2) && 740ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (entry->name3 == name3)) 741ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(entry->payload); 742ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 743ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 744ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for (entry = &(table->table[key]); entry != NULL; entry = entry->next) { 745ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((xmlStrEqual(entry->name, name)) && 746ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrEqual(entry->name2, name2)) && 747ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrEqual(entry->name3, name3))) 748ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(entry->payload); 749ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 750ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 751ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 752ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 753ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 754ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashQLookup3: 755ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 756ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @prefix: the prefix of the userdata 757ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 758ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @prefix2: the second prefix of the userdata 759ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata 760ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @prefix3: the third prefix of the userdata 761ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name3: a third name of the userdata 762ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 763ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Find the userdata specified by the (@name, @name2, @name3) tuple. 764ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 765ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns the a pointer to the userdata 766ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 767ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid * 768ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashQLookup3(xmlHashTablePtr table, 769ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *prefix, const xmlChar *name, 770ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *prefix2, const xmlChar *name2, 771ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *prefix3, const xmlChar *name3) { 772ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project unsigned long key; 773ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr entry; 774ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 775ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table == NULL) 776ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 777ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (name == NULL) 778ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 779ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project key = xmlHashComputeQKey(table, prefix, name, prefix2, 780ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project name2, prefix3, name3); 781ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[key].valid == 0) 782ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 783ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for (entry = &(table->table[key]); entry != NULL; entry = entry->next) { 784ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((xmlStrQEqual(prefix, name, entry->name)) && 785ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrQEqual(prefix2, name2, entry->name2)) && 786ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlStrQEqual(prefix3, name3, entry->name3))) 787ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(entry->payload); 788ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 789ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 790ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 791ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 792ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projecttypedef struct { 793ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashScanner hashscanner; 794ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project void *data; 795ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} stubData; 796ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 797ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectstatic void 798ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectstubHashScannerFull (void *payload, void *data, const xmlChar *name, 799ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2 ATTRIBUTE_UNUSED, 800ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name3 ATTRIBUTE_UNUSED) { 801ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project stubData *stubdata = (stubData *) data; 802ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project stubdata->hashscanner (payload, stubdata->data, (xmlChar *) name); 803ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 804ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 805ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 806ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashScan: 807ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 808ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the scanner function for items in the hash 809ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @data: extra data passed to f 810ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 811ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Scan the hash @table and applied @f to each value. 812ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 813ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid 814ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashScan(xmlHashTablePtr table, xmlHashScanner f, void *data) { 815ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project stubData stubdata; 816ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project stubdata.data = data; 817ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project stubdata.hashscanner = f; 818ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashScanFull (table, stubHashScannerFull, &stubdata); 819ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 820ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 821ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 822ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashScanFull: 823ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 824ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the scanner function for items in the hash 825ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @data: extra data passed to f 826ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 827ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Scan the hash @table and applied @f to each value. 828ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 829ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid 830ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashScanFull(xmlHashTablePtr table, xmlHashScannerFull f, void *data) { 831ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project int i, nb; 832ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr iter; 833ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr next; 834ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 835ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table == NULL) 836ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return; 837ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (f == NULL) 838ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return; 839ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 840ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table) { 841ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for(i = 0; i < table->size; i++) { 842ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[i].valid == 0) 843ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project continue; 844ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = &(table->table[i]); 845ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while (iter) { 846ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project next = iter->next; 847ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project nb = table->nbElems; 848ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((f != NULL) && (iter->payload != NULL)) 849ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project f(iter->payload, data, iter->name, 850ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter->name2, iter->name3); 851ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (nb != table->nbElems) { 852ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project /* table was modified by the callback, be careful */ 853ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (iter == &(table->table[i])) { 854ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[i].valid == 0) 855ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = NULL; 856ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[i].next != next) 857ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = &(table->table[i]); 858ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else 859ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = next; 860ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else 861ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = next; 862ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 863ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 864ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 865ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 866ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 867ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 868ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashScan3: 869ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 870ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata or NULL 871ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata or NULL 872ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name3: a third name of the userdata or NULL 873ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the scanner function for items in the hash 874ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @data: extra data passed to f 875ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 876ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Scan the hash @table and applied @f to each value matching 877ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * (@name, @name2, @name3) tuple. If one of the names is null, 878ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * the comparison is considered to match. 879ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 880ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid 881ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashScan3(xmlHashTablePtr table, const xmlChar *name, 882ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2, const xmlChar *name3, 883ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashScanner f, void *data) { 884ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashScanFull3 (table, name, name2, name3, 885ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (xmlHashScannerFull) f, data); 886ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 887ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 888ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 889ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashScanFull3: 890ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 891ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata or NULL 892ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata or NULL 893ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name3: a third name of the userdata or NULL 894ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the scanner function for items in the hash 895ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @data: extra data passed to f 896ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 897ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Scan the hash @table and applied @f to each value matching 898ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * (@name, @name2, @name3) tuple. If one of the names is null, 899ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * the comparison is considered to match. 900ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 901ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectvoid 902ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashScanFull3(xmlHashTablePtr table, const xmlChar *name, 903ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2, const xmlChar *name3, 904ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashScannerFull f, void *data) { 905ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project int i; 906ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr iter; 907ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr next; 908ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 909ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table == NULL) 910ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return; 911ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (f == NULL) 912ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return; 913ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 914ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table) { 915ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for(i = 0; i < table->size; i++) { 916ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[i].valid == 0) 917ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project continue; 918ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = &(table->table[i]); 919ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while (iter) { 920ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project next = iter->next; 921ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (((name == NULL) || (xmlStrEqual(name, iter->name))) && 922ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project ((name2 == NULL) || (xmlStrEqual(name2, iter->name2))) && 923ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project ((name3 == NULL) || (xmlStrEqual(name3, iter->name3))) && 924ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project (iter->payload != NULL)) { 925ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project f(iter->payload, data, iter->name, 926ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter->name2, iter->name3); 927ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 928ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = next; 929ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 930ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 931ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 932ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 933ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 934ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 935ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashCopy: 936ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 937ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the copier function for items in the hash 938ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 939ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Scan the hash @table and applied @f to each value. 940ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 941ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns the new table or NULL in case of error. 942ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 943ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashTablePtr 944ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashCopy(xmlHashTablePtr table, xmlHashCopier f) { 945ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project int i; 946ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr iter; 947ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr next; 948ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashTablePtr ret; 949ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 950ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table == NULL) 951ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 952ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (f == NULL) 953ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(NULL); 954ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 955ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project ret = xmlHashCreate(table->size); 956ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table) { 957ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for(i = 0; i < table->size; i++) { 958ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[i].valid == 0) 959ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project continue; 960ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = &(table->table[i]); 961ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project while (iter) { 962ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project next = iter->next; 963ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashAddEntry3(ret, iter->name, iter->name2, 964ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter->name3, f(iter->payload, iter->name)); 965ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project iter = next; 966ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 967ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 968ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 969ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project ret->nbElems = table->nbElems; 970ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(ret); 971ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 972ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 973ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 974ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashSize: 975ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 976ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 977ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Query the number of elements installed in the hash @table. 978ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 979ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns the number of elements in the hash table or 980ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * -1 in case of error 981ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 982ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectint 983ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashSize(xmlHashTablePtr table) { 984ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table == NULL) 985ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 986ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(table->nbElems); 987ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 988ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 989ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 990ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashRemoveEntry: 991ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 992ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 993ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the deallocator function for removed item (if any) 994ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 995ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Find the userdata specified by the @name and remove 996ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * it from the hash @table. Existing userdata for this tuple will be removed 997ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * and freed with @f. 998ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 999ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns 0 if the removal succeeded and -1 in case of error or not found. 1000ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 1001ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectint xmlHashRemoveEntry(xmlHashTablePtr table, const xmlChar *name, 1002ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashDeallocator f) { 1003ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(xmlHashRemoveEntry3(table, name, NULL, NULL, f)); 1004ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 1005ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 1006ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 1007ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashRemoveEntry2: 1008ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 1009ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 1010ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata 1011ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the deallocator function for removed item (if any) 1012ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 1013ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Find the userdata specified by the (@name, @name2) tuple and remove 1014ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * it from the hash @table. Existing userdata for this tuple will be removed 1015ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * and freed with @f. 1016ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 1017ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns 0 if the removal succeeded and -1 in case of error or not found. 1018ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 1019ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectint 1020ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashRemoveEntry2(xmlHashTablePtr table, const xmlChar *name, 1021ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2, xmlHashDeallocator f) { 1022ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(xmlHashRemoveEntry3(table, name, name2, NULL, f)); 1023ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 1024ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 1025ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project/** 1026ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * xmlHashRemoveEntry3: 1027ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @table: the hash table 1028ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name: the name of the userdata 1029ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name2: a second name of the userdata 1030ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @name3: a third name of the userdata 1031ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * @f: the deallocator function for removed item (if any) 1032ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 1033ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Find the userdata specified by the (@name, @name2, @name3) tuple and remove 1034ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * it from the hash @table. Existing userdata for this tuple will be removed 1035ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * and freed with @f. 1036ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * 1037ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project * Returns 0 if the removal succeeded and -1 in case of error or not found. 1038ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project */ 1039ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Projectint 1040ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source ProjectxmlHashRemoveEntry3(xmlHashTablePtr table, const xmlChar *name, 1041ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project const xmlChar *name2, const xmlChar *name3, xmlHashDeallocator f) { 1042ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project unsigned long key; 1043ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr entry; 1044ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlHashEntryPtr prev = NULL; 1045ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 1046ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table == NULL || name == NULL) 1047ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 1048ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 1049ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project key = xmlHashComputeKey(table, name, name2, name3); 1050ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->table[key].valid == 0) { 1051ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 1052ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 1053ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project for (entry = &(table->table[key]); entry != NULL; entry = entry->next) { 1054ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (xmlStrEqual(entry->name, name) && 1055ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlStrEqual(entry->name2, name2) && 1056ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlStrEqual(entry->name3, name3)) { 1057ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if ((f != NULL) && (entry->payload != NULL)) 1058ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project f(entry->payload, entry->name); 1059ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->payload = NULL; 1060ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (table->dict == NULL) { 1061ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if(entry->name) 1062ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(entry->name); 1063ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if(entry->name2) 1064ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(entry->name2); 1065ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if(entry->name3) 1066ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(entry->name3); 1067ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 1068ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if(prev) { 1069ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project prev->next = entry->next; 1070ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(entry); 1071ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 1072ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project if (entry->next == NULL) { 1073ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry->valid = 0; 1074ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } else { 1075ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project entry = entry->next; 1076ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project memcpy(&(table->table[key]), entry, sizeof(xmlHashEntry)); 1077ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project xmlFree(entry); 1078ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 1079ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 1080ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project table->nbElems--; 1081ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(0); 1082ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 1083ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project prev = entry; 1084ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 1085ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project return(-1); 1086ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project } 1087ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project} 1088ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project 1089ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#define bottom_hash 1090ab4e2e90f63db6b1cd8bb2e453cac899ef43d42bThe Android Open Source Project#include "elfgcchack.h" 1091