00001 /* 00002 00003 Copyright (c) 2005-2008, Simon Howard 00004 00005 Permission to use, copy, modify, and/or distribute this software 00006 for any purpose with or without fee is hereby granted, provided 00007 that the above copyright notice and this permission notice appear 00008 in all copies. 00009 00010 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 00011 WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 00012 WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 00013 AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 00014 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00015 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00016 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 00017 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00018 00019 */ 00020 00045 #ifndef ALGORITHM_HASH_TABLE_H 00046 #define ALGORITHM_HASH_TABLE_H 00047 00048 #ifdef __cplusplus 00049 extern "C" { 00050 #endif 00051 00056 typedef struct _HashTable HashTable; 00057 00062 typedef struct _HashTableIterator HashTableIterator; 00063 00068 typedef struct _HashTableEntry HashTableEntry; 00069 00074 typedef void *HashTableKey; 00075 00080 typedef void *HashTableValue; 00081 00086 struct _HashTableIterator { 00087 HashTable *hash_table; 00088 HashTableEntry *next_entry; 00089 int next_chain; 00090 }; 00091 00096 #define HASH_TABLE_NULL ((void *) 0) 00097 00106 typedef unsigned long (*HashTableHashFunc)(HashTableKey value); 00107 00115 typedef int (*HashTableEqualFunc)(HashTableKey value1, HashTableKey value2); 00116 00122 typedef void (*HashTableKeyFreeFunc)(HashTableKey value); 00123 00129 typedef void (*HashTableValueFreeFunc)(HashTableValue value); 00130 00143 HashTable *hash_table_new(HashTableHashFunc hash_func, 00144 HashTableEqualFunc equal_func); 00145 00152 void hash_table_free(HashTable *hash_table); 00153 00163 void hash_table_register_free_functions(HashTable *hash_table, 00164 HashTableKeyFreeFunc key_free_func, 00165 HashTableValueFreeFunc value_free_func); 00166 00179 int hash_table_insert(HashTable *hash_table, 00180 HashTableKey key, 00181 HashTableValue value); 00182 00192 HashTableValue hash_table_lookup(HashTable *hash_table, 00193 HashTableKey key); 00194 00204 int hash_table_remove(HashTable *hash_table, HashTableKey key); 00205 00213 int hash_table_num_entries(HashTable *hash_table); 00214 00223 void hash_table_iterate(HashTable *hash_table, HashTableIterator *iter); 00224 00235 int hash_table_iter_has_more(HashTableIterator *iterator); 00236 00246 HashTableValue hash_table_iter_next(HashTableIterator *iterator); 00247 00248 #ifdef __cplusplus 00249 } 00250 #endif 00251 00252 #endif /* #ifndef ALGORITHM_HASH_TABLE_H */ 00253