-
Notifications
You must be signed in to change notification settings - Fork 1
/
hash.h
64 lines (47 loc) · 1.01 KB
/
hash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef _HASH_H
#define _HASH_H
typedef struct _ht_item_t
{
char *k;
void *v;
struct _ht_t *container;
}ht_item_t;
typedef long ht_size_t;
typedef struct _hash_func_data_t
{
char *str;
ht_size_t ht_size;
int i;
}hash_func_data_t;
typedef ht_size_t (*hash_func_t)(hash_func_data_t *);
typedef void (*data_dtor_func_t)(void *);
typedef ht_size_t (*prime_finder_func_t)(ht_size_t);
typedef struct _ht_t
{
ht_size_t base_size;
ht_size_t size;
ht_size_t count;
ht_item_t **items;
data_dtor_func_t data_dtor;
prime_finder_func_t prime_finder;
hash_func_t hash_func;
}ht_t;
ht_item_t *
ht_item_create(char *k, void *v);
int
_ht_item_destroy(ht_item_t *i, data_dtor_func_t dtor);
int
ht_item_destroy(ht_item_t *i);
ht_t *
_ht_create(int bs, data_dtor_func_t dtor, prime_finder_func_t pf, hash_func_t hf);
ht_t *
ht_create(data_dtor_func_t dtor);
int
ht_destroy(ht_t *ht);
int
ht_add(ht_t *ht, ht_item_t *item, int flags);
void *
ht_search(ht_t *ht, char *k);
int
ht_delete(ht_t *ht, char *k);
#endif // _HASH_H