X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=dummynet%2Fhashtable.c;h=3e055f0612a6c678b69834a40213387d0c63f9aa;hb=127aebb5ecac745bb693162d78d489ccba6273b9;hp=30c3b4c363a88010dfb0ebaa7798557c05fbe7d2;hpb=5ad9fec40da13c449d50def12f9cea6e24b6a708;p=ipfw.git diff --git a/dummynet/hashtable.c b/dummynet/hashtable.c index 30c3b4c..3e055f0 100644 --- a/dummynet/hashtable.c +++ b/dummynet/hashtable.c @@ -13,13 +13,13 @@ struct new_obj { }; /* 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 */ @@ -34,17 +34,15 @@ struct new_hash_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; @@ -64,7 +62,7 @@ new_table_init (int size, int obj_size, } 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; @@ -73,7 +71,7 @@ new_table_insert_obj (struct new_hash_table *h, const void *obj) /* 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 */ @@ -92,7 +90,7 @@ new_table_insert_obj (struct new_hash_table *h, const void *obj) } 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; @@ -100,7 +98,7 @@ new_table_delete_obj(struct new_hash_table *h, const void *obj) 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) @@ -115,7 +113,7 @@ new_table_delete_obj(struct new_hash_table *h, const void *obj) } 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; @@ -124,14 +122,14 @@ new_table_extract_obj(struct new_hash_table *h, const void *obj) 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; @@ -152,18 +150,17 @@ new_table_destroy(struct new_hash_table *h) /* 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) { @@ -178,7 +175,7 @@ table_next(struct new_hash_table *h, const void *o) */ 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)