5 #include <stddef.h> /* for size_t type */
6 #include <stdio.h> /* for FILE */
10 typedef struct hnode
{
13 TAILQ_ENTRY(hnode
) hn_next
;
16 /* Type definitions for use in callback functions */
17 typedef size_t hashf_t(const void *key
);
18 typedef int cmpf_t(const void *arg1
, const void *arg2
);
19 typedef void printf_t(const void *key
, const void *data
);
21 typedef struct htable
{
23 size_t ht_grows
; /* number of automatic resizes */
25 size_t ht_size
; /* size must be a power of 2 */
26 size_t ht_used
; /* number of hash table entries */
28 size_t ht_limit
; /* limit = factor * size */
29 hashf_t
*ht_hashf
; /* pointer to hash function */
30 cmpf_t
*ht_cmpf
; /* pointer to compare function */
31 printf_t
*ht_printf
; /* pointer to printf function */
32 TAILQ_HEAD(htablehead
, hnode
) *ht_table
;
35 typedef struct htablehead hhead_t
;
37 typedef struct htable_iterator
{
54 /* Function prototypes */
55 htret_t
htable_init(htable_t
*htable
, size_t size
, size_t factor
,
59 void htable_free(htable_t
*htable
);
60 htret_t
htable_free_obj(htable_t
*htable
, void *key
, htfree_t htfree
);
61 void htable_free_all_obj(htable_t
*htable
, htfree_t htfree
);
62 htret_t
htable_grow(htable_t
*htable
);
63 htret_t
htable_insert(htable_t
*htable
, void *key
, void *data
);
64 htret_t
htable_remove(htable_t
*htable
, const void *key
);
65 void *htable_search(const htable_t
*htable
, const void *key
);
66 void htable_print(const htable_t
*htable
, FILE *fp
);
67 size_t htable_get_size(const htable_t
*htable
);
68 size_t htable_get_used(const htable_t
*htable
);
69 void htable_traverse(const htable_t
*htable
, void (*pfunc
)(void *data
));
70 void htable_iterator_init(htable_iterator_t
*it
);
71 void *htable_iterator_get_data(const htable_iterator_t it
);
72 void *htable_iterator_get_key(const htable_iterator_t it
);
73 const hnode_t
*htable_get_next_elm(const htable_t
*htable
, htable_iterator_t
*it
);
76 size_t htable_stat_get_grows(const htable_t
*htable
);
77 size_t htable_stat_get_chain_len(const htable_t
*htable
, size_t pos
);