1 /* this is the brisby fancy hashtable */
2 #ifndef __ht_h
3 #define __ht_h
4 
5 typedef struct {
6 	void *key;
7 	unsigned klen;
8 	unsigned long hash;
9 	void *data;
10 	int free_data;
11 	int idata;
12 
13 	void *next;
14 } htbucket;
15 typedef struct {
16 	unsigned s;
17 	htbucket **b;
18 	unsigned long (*hash)(const void *,unsigned);
19 	int (*ondel)(void *);
20 
21 	/* useful for to-disk journaling */
22 	void (*onwrite)(const void *key, unsigned klen, const void *data);
23 	int (*onfail)(const void *key, unsigned klen);
24 } ht;
25 
26 enum {	HT_RESTART,
27 	HT_FAILNOW, HT_SUCCESSNOW,
28 	HT_TRIPSUCCESS, HT_TRIPFAIL,
29 	HT_WILLSUCCESS, HT_WILLFAIL,
30 	HT_NEXT, HT_AGAIN,
31 };
32 
33 int ht_init(ht *x, unsigned tab, unsigned long (*hash)(const void *, unsigned));
34 int ht_die(ht *x);
35 int ht_walk(ht *x, int (*fn)(ht *, void *, unsigned, void *));
36 int ht_store(ht *x, const void *, unsigned, void *);
37 int ht_storeint(ht *x, const void *, unsigned, int i);
38 int ht_storecopy(ht *x, const void *, unsigned, void *, unsigned);
39 void *ht_fetch(ht *x, const void *, unsigned);
40 int ht_fetchint(ht *x, const void *, unsigned);
41 int ht_delete(ht *x, const void *, unsigned);
42 
43 int ht_ondelete(ht *x, int (*fn)(void *data));
44 int ht_onwrite(ht *x, void (*fn)(const void *,unsigned,const void *));
45 int ht_onfail(ht *x, int (*fn)(const void *, unsigned));
46 
47 #endif
48