/*1Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.2All rights reserved.3Copyright (C) 2007-2010, Gabriel Dos Reis.4All rights reserved.56Redistribution and use in source and binary forms, with or without7modification, are permitted provided that the following conditions are8met:910- Redistributions of source code must retain the above copyright11notice, this list of conditions and the following disclaimer.1213- Redistributions in binary form must reproduce the above copyright14notice, this list of conditions and the following disclaimer in15the documentation and/or other materials provided with the16distribution.1718- Neither the name of The Numerical ALgorithms Group Ltd. nor the19names of its contributors may be used to endorse or promote products20derived from this software without specific prior written permission.2122THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS23IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED24TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A25PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER26OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,27EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,28PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR29PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF30LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING31NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS32SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.33*/3435#ifndef OPENAXIOM_HASH_INCLUDED36#define OPENAXIOM_HASH_INCLUDED3738struct HashEntry {39const char *key; /* pointer to key data */40char *data; /* Pointer to entry */41struct HashEntry *next; /* Link to next entry */42};4344typedef int (*EqualFunction)(const void*, const void*);45typedef int (*HashcodeFunction)(const void*,int);46typedef void (*MappableFunction) (const void*);47typedef void (*FreeFunction) (void *);48struct HashTable {49HashEntry **table; /* the actual table */50int size; /* size of table */51int num_entries; /* number of elements in a hash table */52EqualFunction equal; /* equality predicate for keys */53HashcodeFunction hash_code; /* create hash code for a key */54};5556extern char* alloc_string(const char*);57extern HashEntry* hash_copy_entry(HashEntry*);58extern HashTable* hash_copy_table(HashTable*);59extern void hash_delete(HashTable*, const char*);60extern char* hash_find(HashTable*, const char*);61extern void hash_init(HashTable*, int, EqualFunction, HashcodeFunction);62extern void free_hash(HashTable*, FreeFunction);63extern void hash_insert(HashTable*, char*, const char*);64extern void hash_map(HashTable*, MappableFunction func);65extern char* hash_replace(HashTable*, char*, const char*);66extern int string_equal(const char*, const char*);67extern int string_hash(const char*, int size);6869#endif /* OPENAXIOM_HASH_INCLUDED */707172