#ifndef __HASHTABLE_H_ #define __HASHTABLE_H_ /* * new_table_init creates a table with the specified * number of buckets (size). * obj_size is the size of individual objects (key+value), * the first function is the hash function (called with the * size and the payload pointer) * the second function is the compare function, to tell if two * objects are the same (XXX we could spare this if we also * pass a key_size and use a bcmp for comparisons) * Not extensible at the moment. */ struct malloc_type; struct ipfw_ht; struct ipfw_ht* ipfw_ht_new(int size, int obj_size, uint32_t (hash_fn)(const void *, uint32_t size), int (cmp_fn)(const void*, const void*, int sz), struct malloc_type *mtype); void *ipfw_ht_destroy(struct ipfw_ht *h); /* add a new object to the table, return success/failure */ int ipfw_ht_insert(struct ipfw_ht *h, const void *obj); /* * returns a pointer to the matching object or NULL if not found. * No refcounts. */ const void *ipfw_ht_extract(struct ipfw_ht *h, const void *key); /* remove an object from the table */ int ipfw_ht_remove(struct ipfw_ht *h, const void *key); /* return the number of elements in the table */ int ipfw_ht_count(const struct ipfw_ht *h); /* returns the first or next element. Works by hashing the * current object and then finds the next one. * If obj == NULL returns the first object in the table */ const void *ipfw_ht_next(struct ipfw_ht *h, const void *obj); #endif