blob: 1a5fc92c3ea383d7f52fabace93cb88d371caa4f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include "config.h"
#include <assert.h>
#include <errno.h>
#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 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);
}
|