summaryrefslogtreecommitdiffstats
path: root/include/hash.h
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2009-01-15 23:19:57 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2009-01-15 23:19:57 +0100
commit50339f96638eed35dac2b673b64cc6f1eb96406c (patch)
tree20dbb60fd3c41994da7cd7ad8888185c681fadb1 /include/hash.h
parentb28224b0326636ff5832b38817b7720f48070ee7 (diff)
src: rework of the hash-cache infrastructure
Currently, the caching system is implemented in a two layer architecture: hashtable (inner layer) and cache (upper layer). This patch reworks the hash-cache infrastructure to solve some initial design problems to make it more flexible, the main strong points of this patch are: * Memory handling is done in the cache layer, not in the inner hashtable layer. This removes one of the main dependencies between the hashtable and the cache classes. * Remove excessive encapsulation: the former cache used to hide a lot of details of the inner hashtable implementation. * Fix over-hashing of some operations: lookup-delete-add required three hash calculations. Similarly, the update-or-add operation required two hash calculations. Now, we calculate the hash once and re-use the value how many times as we need. This patch simplifies the caching system. As a result, we save ~130 lines of code. Small code means and less complexity means less chance to have bugs. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include/hash.h')
-rw-r--r--include/hash.h22
1 files changed, 8 insertions, 14 deletions
diff --git a/include/hash.h b/include/hash.h
index 2fb0a27..68d618b 100644
--- a/include/hash.h
+++ b/include/hash.h
@@ -2,7 +2,6 @@
#define _NF_SET_HASH_H_
#include <unistd.h>
-#include "slist.h"
#include "linux_list.h"
#include <stdint.h>
@@ -15,35 +14,30 @@ 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);
- struct slist_head members[0];
+ struct list_head members[0];
};
struct hashtable_node {
- struct slist_head head;
- char data[0];
+ struct list_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,
+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_find(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, struct hashtable_node *n));
unsigned int hashtable_counter(const struct hashtable *table);
#endif