diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-14 17:36:03 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-14 17:36:03 +0100 |
commit | 74ea640f40285220dfa93492a143a35426b867d1 (patch) | |
tree | 726fea60a2e0a9f835212228238bdc479012b2f8 /src/common/libalgo/keyval.c | |
parent | ba53137f1b687b1c9cbd66fbe306ed1bf6d0cccb (diff) | |
download | kogata-74ea640f40285220dfa93492a143a35426b867d1.tar.gz kogata-74ea640f40285220dfa93492a143a35426b867d1.zip |
Add binary tree implementation. NOT TESTED, FULL OF BUGS.
Diffstat (limited to 'src/common/libalgo/keyval.c')
-rw-r--r-- | src/common/libalgo/keyval.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/common/libalgo/keyval.c b/src/common/libalgo/keyval.c new file mode 100644 index 0000000..0368aed --- /dev/null +++ b/src/common/libalgo/keyval.c @@ -0,0 +1,51 @@ +#include <malloc.h> +#include <string.h> + +#include <algo.h> + +// Hashing and comparing + +hash_t id_hash_fun(const void* v) { + return (hash_t)v; +} + +hash_t str_hash_fun(const void* v) { + hash_t h = 712; + for (char* s = (char*)v; *s != 0; s++) { + h = h * 101 + *s; + } + return h; +} + +bool id_key_eq_fun(const void* a, const void* b) { + return a == b; +} + +bool str_key_eq_fun(const void* a, const void* b) { + return strcmp((const char*)a, (const char*)b) == 0; +} + +int id_key_cmp_fun(const void* a, const void* b) { + return (b == a ? 0 : (b > a ? 1 : -1)); +} + +int str_key_cmp_fun(const void* a, const void* b) { + return strcmp((const char*)a, (const char*)b); +} + +// Freeing functions + +void free_key(void* key, void* val) { + free(key); +} + +void free_val(void* key, void* val) { + free(val); +} + +void free_key_val(void* key, void* val) { + free(key); + free(val); +} + +/* vim: set ts=4 sw=4 tw=0 noet :*/ |