cctools
hash_table.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3 Copyright (C) 2022 The University of Notre Dame
4 This software is distributed under the GNU General Public License.
5 See the file COPYING for details.
6 */
7 
8 #ifndef HASH_TABLE_H
9 #define HASH_TABLE_H
10 
41 typedef unsigned (*hash_func_t) (const char *key);
42 
49 struct hash_table *hash_table_create(int buckets, hash_func_t func);
50 
56 void hash_table_clear(struct hash_table *h, void (*delete_func)( void *) );
57 
58 
64 void hash_table_delete(struct hash_table *h);
65 
71 int hash_table_size(struct hash_table *h);
72 
83 int hash_table_insert(struct hash_table *h, const char *key, const void *value);
84 
91 void *hash_table_lookup(struct hash_table *h, const char *key);
92 
99 void *hash_table_remove(struct hash_table *h, const char *key);
100 
108 void hash_table_firstkey(struct hash_table *h);
109 
118 int hash_table_nextkey(struct hash_table *h, char **key, void **value);
119 
125 unsigned hash_string(const char *s);
126 
141 #define HASH_TABLE_ITERATE( table, key, value ) hash_table_firstkey(table); while(hash_table_nextkey(table,&key,(void**)&value))
142 
143 #endif
int hash_table_insert(struct hash_table *h, const char *key, const void *value)
Insert a key and value.
void * hash_table_remove(struct hash_table *h, const char *key)
Remove a value by key.
unsigned hash_string(const char *s)
A default hash function.
struct hash_table * hash_table_create(int buckets, hash_func_t func)
Create a new hash table.
unsigned(* hash_func_t)(const char *key)
The type signature for a hash function given to hash_table_create.
Definition: hash_table.h:41
int hash_table_size(struct hash_table *h)
Count the entries in a hash table.
void hash_table_clear(struct hash_table *h, void(*delete_func)(void *))
Remove all entries from an hash table.
void * hash_table_lookup(struct hash_table *h, const char *key)
Look up a value by key.
int hash_table_nextkey(struct hash_table *h, char **key, void **value)
Continue iteration over all keys.
void hash_table_firstkey(struct hash_table *h)
Begin iteration over all keys.
void hash_table_delete(struct hash_table *h)
Delete a hash table.