diff options
author | EuAndreh <eu@euandre.org> | 2024-06-04 10:33:12 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-06-04 10:33:12 -0300 |
commit | 160a9d47882544aea32191349429dfe5c7f3ca12 (patch) | |
tree | 1276cd6917eb931f2d2f1065840715eeb7bdbaea /src | |
parent | src/vector.h: Implement vector_assign() (diff) | |
download | pindaiba-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.c | 26 | ||||
-rw-r--r-- | src/set.h | 1 |
2 files changed, 25 insertions, 2 deletions
@@ -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; } @@ -0,0 +1 @@ +struct Set; |