aboutsummaryrefslogtreecommitdiff
path: root/src/common/include/hashtbl.h
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-09 17:56:59 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-09 17:56:59 +0100
commit002a1b035e2464c11b17f1bfd3835deccef7652a (patch)
tree640baf35dce60566a8f14eec54212af848e5ad71 /src/common/include/hashtbl.h
parentf2c51bc81d2aa618b29ddbeaae5ac1c5308821f0 (diff)
downloadkogata-002a1b035e2464c11b17f1bfd3835deccef7652a.tar.gz
kogata-002a1b035e2464c11b17f1bfd3835deccef7652a.zip
Change readme, remove unused code, changed hashtbl to add key freeing function.
Diffstat (limited to 'src/common/include/hashtbl.h')
-rw-r--r--src/common/include/hashtbl.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/common/include/hashtbl.h b/src/common/include/hashtbl.h
index 16dfefb..3b5a44d 100644
--- a/src/common/include/hashtbl.h
+++ b/src/common/include/hashtbl.h
@@ -8,8 +8,10 @@
// Supports adding, seeking, removing
// When adding a binding to the table, the previous binding for same key (if exists) is removed
-// TODO : possibility to allocate the hashtbl structure on any heap
-// (currently uses kmalloc/kfree)
+// The hashtbl is allocated with malloc/free
+// The keys are not copied in any way by the hashtbl, but there might still be something
+// to free, so the create_hashtbl function is given a key freeing function, usually
+// null when no freeing is required, or the standard free function.
struct hashtbl;
typedef struct hashtbl hashtbl_t;
@@ -17,8 +19,9 @@ typedef struct hashtbl hashtbl_t;
typedef size_t hash_t;
typedef hash_t (*hash_fun_t)(const void*);
typedef bool (*key_eq_fun_t)(const void*, const void*);
+typedef void (*key_free_fun_t)(void*);
-hashtbl_t* create_hashtbl(key_eq_fun_t ef, hash_fun_t hf, size_t initial_size); // 0 -> default size
+hashtbl_t* create_hashtbl(key_eq_fun_t ef, hash_fun_t hf, key_free_fun_t ff, size_t initial_size); // 0 -> default size
void delete_hashtbl(hashtbl_t* ht);
int hashtbl_add(hashtbl_t* ht, void* key, void* v); // non-null on error (OOM for instance)