};
/* Hash table */
-struct new_hash_table {
+struct ipfw_ht {
int table_size; /* Size of the table (buckets) */
int table_obj; /* number of object in the table */
int obj_size; /* size of object (key + value) */
/* Hash function for this table */
uint32_t (*hash)(const void *key, uint32_t size);
- int (*cmp)(const void *obj1, const void *obj2);
+ int (*cmp)(const void *obj1, const void *obj2, int sz);
int hash_arg; /* hash function parameter */
struct malloc_type *mtype;
struct new_obj **table_ptr; /* Pointer to the table */
*
* Return value: pointer to the hash table, NULL if error occurs
*/
-struct new_hash_table *
-new_table_init (int size, int obj_size,
+struct ipfw_ht *
+ipfw_ht_new(int size, int obj_size,
uint32_t (hf)(const void *, uint32_t size),
- int (compare)(const void *, const void *),
+ int (compare)(const void *, const void *, int),
struct malloc_type *mtype)
{
- struct new_hash_table *h;
+ struct ipfw_ht *h;
- printf("%s called\n", __FUNCTION__);
-
- h = malloc(sizeof(struct new_hash_table), mtype, M_NOWAIT | M_ZERO);
+ h = malloc(sizeof(*h), mtype, M_NOWAIT | M_ZERO);
if (h == NULL)
return NULL;
}
int
-new_table_insert_obj (struct new_hash_table *h, const void *obj)
+ipfw_ht_insert(struct ipfw_ht *h, const void *obj)
{
int i; /* array index */
struct new_obj *o, *ot;
/* same key not allowed */
for (ot = h->table_ptr[i]; ot; ot = ot->next) {
- if (h->cmp(obj, ot->obj) == 0)
+ if (h->cmp(obj, ot->obj, h->obj_size) == 0)
return 1; /* error */
}
/* allocate a single chunk of memory */
}
int
-new_table_delete_obj(struct new_hash_table *h, const void *obj)
+ipfw_ht_remove(struct ipfw_ht *h, const void *obj)
{
int i;
struct new_obj *obj1, *prev;
i = h->hash(obj, h->table_size);
for (prev = NULL, obj1 = h->table_ptr[i]; obj1; obj1 = obj1->next) {
- if (h->cmp(obj, (void *)obj1->obj) != 0)
+ if (h->cmp(obj, obj1->obj, h->obj_size) != 0)
continue;
/* Object found, delete */
if (prev != NULL)
}
const void *
-new_table_extract_obj(struct new_hash_table *h, const void *obj)
+ipfw_ht_extract(struct ipfw_ht *h, const void *obj)
{
struct new_obj *o;
int i;
i = h->hash(obj, h->table_size);
for (o = h->table_ptr[i]; o; o = o->next) {
- if (h->cmp(o->obj, obj) == 0)
+ if (h->cmp(o->obj, obj, h->obj_size) == 0)
return o->obj;
}
return NULL;
}
void *
-new_table_destroy(struct new_hash_table *h)
+ipfw_ht_destroy(struct ipfw_ht *h)
{
int i;
struct new_obj *cur, *next;
/* returns the number of elements in the table */
int
-new_table_get_element(const struct new_hash_table *h)
+ipfw_ht_count(const struct ipfw_ht *h)
{
return h ? h->table_obj : 0;
}
const void *
-table_next(struct new_hash_table *h, const void *o)
+table_next(struct ipfw_ht *h, const void *o)
{
int i;
struct new_obj *obj;
- printf("%s called\n", __FUNCTION__);
if (h == NULL || h->table_obj == 0)
return NULL;
if (o == NULL) {
*/
i = h->hash(o, h->table_size);
for (obj = h->table_ptr[i]; obj; obj = obj->next) {
- if (h->cmp(obj->obj, o) == 0)
+ if (h->cmp(obj->obj, o, h->obj_size) == 0)
break;
}
if (obj && obj->next != NULL)