summaryrefslogtreecommitdiff
path: root/src/set.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set.c')
-rw-r--r--src/set.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/set.c b/src/set.c
index 3c03231..465a141 100644
--- a/src/set.c
+++ b/src/set.c
@@ -5,26 +5,35 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
+#include <siphashbs.h>
+
+#include "hash.h"
#include "logerr.h"
+#include "tree.h"
#include "util.h"
+#include "vector.h"
#include "set.h"
struct Set {
+ const struct Vector *table;
+ const size_t value_size;
size_t count;
};
int
-set_new(const struct Set **const out) {
+set_new(const size_t value_size, const struct Set **const out) {
int rc = -1;
const struct Set *ret = NULL;
+ const struct Vector *table = NULL;
ret = malloc(sizeof(*ret));
if (ret == NULL) {
@@ -32,13 +41,23 @@ set_new(const struct Set **const out) {
goto out;
}
+ if (vector_new(sizeof(struct Tree *), &table)) {
+ logerr("vector_new()");
+ goto out;
+ }
+
memcpy((void *)ret, &(struct Set) {
- .count = 0U,
+ .table = table,
+ .value_size = value_size,
+ .count = 0U,
}, sizeof(*ret));
*out = ret;
rc = 0;
out:
if (rc) {
+ if (table != NULL) {
+ vector_free(&table);
+ }
if (ret != NULL) {
freeit((void *)&ret);
}
@@ -49,5 +68,8 @@ out:
void
set_free(const struct Set **const s) {
assert((*s) != NULL);
+ const struct Vector *table = (*s)->table;
+ vector_free(&table);
free((void *)*s);
+ *s = NULL;
}