From ec9983fa23bc2e5a9c4bdf06c533c5e8ae483ade Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 11 Jan 2010 19:15:49 +0100 Subject: NFCT: use new hashtable implementation for better performance This patch replaces the existing hashtable implementation with a newer that provide better performance since it reduces the number of hash computations. Signed-off-by: Pablo Neira Ayuso --- include/ulogd/hash.h | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/ulogd/hash.h b/include/ulogd/hash.h index 45d2f48..d4aedb8 100644 --- a/include/ulogd/hash.h +++ b/include/ulogd/hash.h @@ -2,8 +2,7 @@ #define _NF_SET_HASH_H_ #include -#include "slist.h" -#include +#include "linuxlist.h" #include @@ -15,34 +14,31 @@ struct hashtable { uint32_t limit; uint32_t count; uint32_t initval; - uint32_t datasize; + + uint32_t (*hash)(const void *data, const struct hashtable *table); + int (*compare)(const void *data1, const void *data2); - uint32_t (*hash)(const void *data, struct hashtable *table); - int (*compare)(const void *data1, const void *data2); - - struct slist_head members[0]; + struct llist_head members[0]; }; struct hashtable_node { - struct slist_head head; - char data[0]; + struct llist_head head; }; -struct hashtable_node *hashtable_alloc_node(int datasize, void *data); -void hashtable_destroy_node(struct hashtable_node *h); - struct hashtable * -hashtable_create(int hashsize, int limit, int datasize, - uint32_t (*hash)(const void *data, struct hashtable *table), +hashtable_create(int hashsize, int limit, + uint32_t (*hash)(const void *data, + const struct hashtable *table), int (*compare)(const void *data1, const void *data2)); void hashtable_destroy(struct hashtable *h); - -void *hashtable_add(struct hashtable *table, void *data); -void *hashtable_get(struct hashtable *table, const void *data); -int hashtable_del(struct hashtable *table, void *data); +int hashtable_hash(const struct hashtable *table, const void *data); +struct hashtable_node *hashtable_find(const struct hashtable *table, const void *data, int id); +int hashtable_add(struct hashtable *table, struct hashtable_node *n, int id); +void hashtable_del(struct hashtable *table, struct hashtable_node *node); int hashtable_flush(struct hashtable *table); int hashtable_iterate(struct hashtable *table, void *data, - int (*iterate)(void *data1, void *data2)); + int (*iterate)(void *data, void *n)); +int hashtable_iterate_limit(struct hashtable *table, void *data, uint32_t from, uint32_t steps, int (*iterate)(void *data1, void *n)); unsigned int hashtable_counter(const struct hashtable *table); #endif -- cgit v1.2.3