#include "config.h" #include #include #include #include #include #include #include #include #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 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) { logerr("malloc(): %s", strerror(errno)); goto out; } if (vector_new(sizeof(struct Tree *), &table)) { logerr("vector_new()"); goto out; } memcpy((void *)ret, &(struct Set) { .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); } } return rc; } void set_free(const struct Set **const s) { assert((*s) != NULL); const struct Vector *table = (*s)->table; vector_free(&table); freeit((void *)s); }