| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#if !defined(HASH_H_) |
| 17 |
#define HASH_H_ |
| 18 |
|
| 19 |
#include <stdint.h> |
| 20 |
#include <stdlib.h> |
| 21 |
|
| 22 |
typedef void *hash_key_t; |
| 23 |
typedef void *hash_data_t; |
| 24 |
typedef int hash_hashvalue_t; |
| 25 |
typedef hash_hashvalue_t (*hash_func_t)(hash_data_t data); |
| 26 |
typedef int (*hash_cmp_t)(hash_key_t a, hash_key_t b); |
| 27 |
|
| 28 |
struct hash_entry_t; |
| 29 |
|
| 30 |
typedef struct { |
| 31 |
size_t table_size; |
| 32 |
size_t entry_count; |
| 33 |
hash_func_t hashfunc; |
| 34 |
hash_cmp_t keycmp; |
| 35 |
struct hash_entry_t *table; |
| 36 |
struct hash_entry_t *head; |
| 37 |
} hash_table_t; |
| 38 |
|
| 39 |
int create_hashtable(hash_table_t *table, size_t initial_size, hash_func_t func, |
| 40 |
hash_cmp_t keycmp); |
| 41 |
int grow_hashtable(hash_table_t *table, size_t new_size); |
| 42 |
int destroy_hashtable(hash_table_t *table); |
| 43 |
|
| 44 |
int lookup_hashtable(hash_table_t *table, hash_key_t key, hash_data_t *data); |
| 45 |
int addto_hashtable(hash_table_t *table, hash_key_t key, hash_data_t data); |
| 46 |
int removefrom_hashtable(hash_table_t *table, hash_key_t key); |
| 47 |
int foreach_hash_entry(hash_table_t *table, void *opaque, |
| 48 |
int (*cb)(hash_key_t key, hash_data_t data, |
| 49 |
void *opaque)); |
| 50 |
|
| 51 |
hash_hashvalue_t strhash(const char *str); |
| 52 |
|
| 53 |
#endif |