-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.c
More file actions
41 lines (32 loc) · 842 Bytes
/
set.c
File metadata and controls
41 lines (32 loc) · 842 Bytes
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
#include "set.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
static const char dummy_value = '\0';
void set_add(Set *set, const char*key) {
set->map->put(set->map, key, (void*) &dummy_value);
}
bool set_contains(Set *set, const char *key) {
return set->map->get(set->map, key) != NULL;
}
void set_remove(Set *set, const char *key) {
set->map->remove(set->map, key);
}
void set_destroy(Set *set) {
set->map->destroy(set->map);
free(set);
}
Set *set_empty (size_t capacity) {
Set *set = (Set*)malloc(sizeof(Set));
assert(set != NULL);
set->map = MapFactory.empty(capacity);
set->add = set_add;
set->contains = set_contains;
set->remove = set_remove;
set->destroy = set_destroy;
return set;
}
const SetClass SetFactory = {
.empty = set_empty
};