5 #include <stddef.h> /* for size_t type */
12 TAILQ_ENTRY(hnode
) hn_next
;
15 /* Type definitions for use in callback functions */
16 typedef size_t hashf_t(const void *key
);
17 typedef int cmpf_t(const void *arg1
, const void *arg2
);
18 typedef void printf_t(const void *key
, const void *data
);
20 typedef struct htable
{
22 size_t ht_grows
; /* number of automatic resizes */
24 size_t ht_size
; /* size must be a power of 2 */
25 size_t ht_used
; /* number of hash table entries */
27 size_t ht_limit
; /* limit = factor * size */
28 hashf_t
*ht_hashf
; /* pointer to hash function */
29 cmpf_t
*ht_cmpf
; /* pointer to compare function */
30 printf_t
*ht_printf
; /* pointer to printf function */
31 TAILQ_HEAD(htablehead
, hnode
) *ht_table
;
34 typedef struct htablehead hhead_t
;
48 /* Function prototypes */
49 htret_t
htable_init(htable_t
*htable
, size_t size
, size_t factor
,
53 void htable_free(htable_t
*htable
);
54 htret_t
htable_free_obj(htable_t
*htable
, void *key
, htfree_t htfree
);
55 void htable_free_all_obj(htable_t
*htable
, htfree_t htfree
);
56 htret_t
htable_grow(htable_t
*htable
);
57 htret_t
htable_insert(htable_t
*htable
, void *key
, void *data
);
58 htret_t
htable_remove(htable_t
*htable
, const void *key
);
59 void *htable_search(const htable_t
*htable
, const void *key
);
60 void htable_print(const htable_t
*htable
);
61 size_t htable_get_size(const htable_t
*htable
);
62 size_t htable_get_used(const htable_t
*htable
);
63 void htable_traverse(const htable_t
*htable
, void (*pfunc
)(void *data
));
64 const hnode_t
*htable_get_next_elm(const htable_t
*htable
, size_t *pos
, const hnode_t
*pnode
);
67 size_t htable_get_grows(const htable_t
*htable
);