summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-06-04 10:33:12 -0300
committerEuAndreh <eu@euandre.org>2024-06-04 10:33:12 -0300
commit160a9d47882544aea32191349429dfe5c7f3ca12 (patch)
tree1276cd6917eb931f2d2f1065840715eeb7bdbaea /src
parentsrc/vector.h: Implement vector_assign() (diff)
downloadpindaiba-160a9d47882544aea32191349429dfe5c7f3ca12.tar.gz
pindaiba-160a9d47882544aea32191349429dfe5c7f3ca12.tar.xz
src/set.c: Implement set_new() and set_free()
Diffstat (limited to 'src')
-rw-r--r--src/set.c26
-rw-r--r--src/set.h1
2 files changed, 25 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;
}
diff --git a/src/set.h b/src/set.h
index e69de29..5a7377f 100644
--- a/src/set.h
+++ b/src/set.h
@@ -0,0 +1 @@
+struct Set;