diff options
author | EuAndreh <eu@euandre.org> | 2024-06-06 08:46:26 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-06-06 08:46:26 -0300 |
commit | 7d144d9053e54c5c1df04d383e96aac4ee9064bb (patch) | |
tree | d17d2c5c10758144670eb966d3dee9a8f88b1088 | |
parent | src/{tree,vector}.h: Consistent spacing between sections (diff) | |
download | pindaiba-7d144d9053e54c5c1df04d383e96aac4ee9064bb.tar.gz pindaiba-7d144d9053e54c5c1df04d383e96aac4ee9064bb.tar.xz |
src/set.c: v0 for set_add()
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/set.c | 24 | ||||
-rw-r--r-- | tests/set.c | 15 |
3 files changed, 40 insertions, 1 deletions
@@ -16,7 +16,7 @@ MANDIR = $(SHAREDIR)/man EXEC = ./ ## Where to store the installation. Empty by default. DESTDIR = -LDLIBS = -lpthread -lsiphashbs +LDLIBS = -lpthread -lendiannessbs -lsiphashbs @@ -8,6 +8,7 @@ #include <stdint.h> #include <string.h> +#include <endiannessbs.h> #include <siphashbs.h> #include "hash.h" @@ -85,3 +86,26 @@ set_free(const struct Set **const s) { vector_free(&table); freeit((void *)s); } + +int +set_add(const struct Set *const s, const void *const value) { + int rc = -1; + + uint8_t hash_bytes[HASH_OUTPUT_LENGTH]; + hash(s->value_size, value, hash_bytes); + + const uint64_t hash_value = endiannessbs_from_le64(hash_bytes); + const size_t idx = hash_value % vector_capacity(s->table); + + const struct Tree *slot; + assert(vector_nth(s->table, idx, (void *)&slot) == 0); + + if (tree_add(slot, value)) { + logerr("tree_add()"); + goto out; + } + + rc = 0; +out: + return rc; +} diff --git a/tests/set.c b/tests/set.c index e00a253..8148895 100644 --- a/tests/set.c +++ b/tests/set.c @@ -66,6 +66,16 @@ out: return rc; } +static int +test_set_add(void) { + int rc = -1; + + // FIXME + + rc = 0; + return rc; +} + int main(void) { @@ -81,6 +91,11 @@ main(void) { goto out; } + if (test_set_add()) { + logerr("test_set_add()"); + goto out; + } + rc = EXIT_SUCCESS; out: return rc; |