diff options
author | Katharina Fey <kookie@spacekookie.de> | 2019-07-13 06:40:05 +0100 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2019-07-13 06:47:21 +0100 |
commit | 9130e47b171c5182ffe6c14eb710fdcb73943de4 (patch) | |
tree | ca76fcc58130b53c794c99adc7658b3b51075639 /bowl.c | |
parent | d0cca976be6fb90f3724911c8a124bce56b3c5f9 (diff) |
Adding initial support for HASH nodes
This PR adds initial support for HASH data nodes in libbowl.
This allows a performant key-value store lookup in a node tree.
The hashing code implements the "murmur" hash, which has shown
good performance over at [`libcuckoo`]. Currently there is no
extended hashing strategy, which should definitely be changed.
[`libcuckoo`]: https://github.com/qaul/libcuckoo
(currently a collision will cause a recursive re-alloc)
Some of the type-level hacks also begs the question if a PAIR
data node might be warranted, even though it would break the
simple design around bowl->data.
Diffstat (limited to 'bowl.c')
-rw-r--r-- | bowl.c | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -1,5 +1,6 @@ #include "bowl.h" #include "array.h" +#include "hash.h" #include <stdlib.h> #include <memory.h> @@ -37,7 +38,7 @@ err_t bowl_malloc(struct bowl **ptr, bowl_t type) return OK; } -err_t bowl_insert(struct bowl *self, struct bowl *new) +err_t bowl_append(struct bowl *self, struct bowl *new) { CHECK(self, INVALID_PARAMS) CHECK(new, INVALID_PARAMS) @@ -52,7 +53,19 @@ err_t bowl_insert(struct bowl *self, struct bowl *new) return OK; } -err_t bowl_insert_key(struct bowl *self, size_t idx, struct bowl *child) +err_t bowl_insert_key(struct bowl *self, char *key, struct bowl *child) +{ + CHECK(self, INVALID_PARAMS) + CHECK(child, INVALID_PARAMS) + CHECK(key, INVALID_PARAMS) + + switch(self->type) { + case HASH: return hash_insert_key(self, key, child); + default: return INVALID_PARAMS; + } +} + +err_t bowl_insert_idx(struct bowl *self, size_t idx, struct bowl *child) { CHECK(self, INVALID_PARAMS) CHECK(child, INVALID_PARAMS) @@ -66,7 +79,7 @@ err_t bowl_insert_key(struct bowl *self, size_t idx, struct bowl *child) } } -err_t bowl_swap_key(struct bowl *self, size_t idx, struct bowl *child, struct bowl **prev) +err_t bowl_swap_idx(struct bowl *self, size_t idx, struct bowl *child, struct bowl **prev) { CHECK(self, INVALID_PARAMS) CHECK(child, INVALID_PARAMS) |