summaryrefslogtreecommitdiff
path: root/set.h
blob: 82292c296427f56ca64dc605ab229e72e196f098 (plain)
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
#ifndef __SAFEC_SET_H
#define __SAFEC_SET_H
#include "types.h"
#include "hash.h"

typedef struct {
    hash_func_t hash_func;
    eq_func_t eq_func;
    double load_limit;

    size_t size;

    size_t __num_buckets;
    void** __buckets;
} set_t;

void set_init(
    set_t* set,
    hash_func_t hash_func,
    eq_func_t eq_func,
    double load_limit);
void set_init_capacity(
    set_t* set,
    hash_func_t hash_func,
    eq_func_t eq_func,
    double load_limit,
    size_t capacity);
void set_destroy(set_t* set);

bool set_contains(const set_t* set, const void* key);
void* set_get(const set_t* set, const void* key);
void* set_get_or_default(const set_t* set, const void* key, void* default_key);
void* set_add(set_t* set, void* key);
void set_put(set_t* set, void* key);
void* set_remove(set_t* set, const void* key);

typedef void (*set_foreach_func_t)(void* key, void* data);
void set_foreach(set_t* set, set_foreach_func_t foreach_func, void* data);

#endif