Grab the lock before reading uid/gid related structure, this will
[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  * max_el and max_ratio currently unused.
15  */
16 struct malloc_type;
17 struct new_hash_table * new_table_init (int size, int obj_size,
18     uint32_t (hash_fn)(const void *, uint32_t size),
19     int (cmp_fn)(const void*, const void*),
20     struct malloc_type *mtype);
21
22 /* add a new object to the table, return success/failure */
23 int new_table_insert_obj (struct new_hash_table *h, const void *obj);
24
25 /*
26  * returns a pointer to the matching object or NULL if not found.
27  * No refcounts.
28  */
29 const void *new_table_extract_obj(struct new_hash_table *h, const void *key);
30
31 /* remove an object from the table */
32 int new_table_delete_obj(struct new_hash_table *h, const void *key);
33 void *new_table_destroy(struct new_hash_table *h);
34
35 /* return the number of elements in the table */
36 int new_table_get_element(const struct new_hash_table *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 *table_next(struct new_hash_table *h, const void *obj);
43
44 #endif