Add htable_grow()
[eleutheria.git] / genstructs / htable / htable.h
blob7fd22dbfe8057d8594e7eb42f248f3c3320dc610
1 #ifndef HTABLE_H
2 #define HTABLE_H
4 #include <sys/queue.h>
6 typedef struct hnode {
7 const void *hn_key;
8 void *hn_data;
9 TAILQ_ENTRY(hnode) hn_next;
10 } hnode_t;
12 typedef struct htable {
13 size_t ht_size; /* size must be a power of 2 */
14 unsigned int ht_used;
15 unsigned int ht_factor;
16 unsigned int ht_limit;
17 unsigned int (*ht_hashf)(const void *key);
18 int (*ht_cmpf)(const void *arg1, const void *arg2);
19 void (*ht_printf)(const void *key, const void *data);
20 TAILQ_HEAD(htablehead, hnode) *ht_table;
21 } htable_t;
23 typedef struct htablehead hhead_t;
25 typedef enum {
26 HT_OK,
27 HT_NOMEM,
28 HT_NOTFOUND
29 } htret_t;
31 /* Function prototypes */
32 htret_t htable_init(htable_t *htable, size_t size, unsigned int factor);
33 void htable_free(htable_t *htable);
34 htret_t htable_grow(htable_t *htable);
35 htret_t htable_insert(htable_t *htable, const void *key, void *data);
36 htret_t htable_remove(htable_t *htable, const void *key);
37 void *htable_search(const htable_t *htable, const void *key);
38 void htable_print(const htable_t *htable);
40 #endif /* HTABLE_H */