summaryrefslogtreecommitdiff
path: root/src/set.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set.c')
-rw-r--r--src/set.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/set.c b/src/set.c
index 978115e..e2baaed 100644
--- a/src/set.c
+++ b/src/set.c
@@ -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;
+}