Work on the radix code, added support to compile on OpenWRT,
[ipfw.git] / dummynet / hashtable.h
1 #ifndef __HASHTABLE_H_
2 #define __HASHTABLE_H_
3
4 /*
5  * new_table_init creates a table with the specified
6  *      number of buckets (size).
7  * obj_size is the size of individual objects (key+value),
8  * the first function is the hash function (called with the
9  *      size and the payload pointer)
10  * the second function is the compare function, to tell if two
11  *      objects are the same (XXX we could spare this if we also
12  *      pass a key_size and use a bcmp for comparisons)
13  * Not extensible at the moment.
14  */
15 struct malloc_type;
16 struct ipfw_ht;
17 struct ipfw_ht* ipfw_ht_new(int size, int obj_size,
18     uint32_t (hash_fn)(const void *, uint32_t size),
19     int (cmp_fn)(const void*, const void*, int sz),
20     struct malloc_type *mtype);
21 void *ipfw_ht_destroy(struct ipfw_ht *h);
22
23 /* add a new object to the table, return success/failure */
24 int ipfw_ht_insert(struct ipfw_ht *h, const void *obj);
25
26 /*
27  * returns a pointer to the matching object or NULL if not found.
28  * No refcounts.
29  */
30 const void *ipfw_ht_extract(struct ipfw_ht *h, const void *key);
31
32 /* remove an object from the table */
33 int ipfw_ht_remove(struct ipfw_ht *h, const void *key);
34
35 /* return the number of elements in the table */
36 int ipfw_ht_count(const struct ipfw_ht *h);
37
38 /* returns the first or next element. Works by hashing the
39  * current object and then finds the next one.
40  * If obj == NULL returns the first object in the table
41  */
42 const void *ipfw_ht_next(struct ipfw_ht *h, const void *obj);
43
44 #endif