-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhashset.h
58 lines (47 loc) · 1.37 KB
/
hashset.h
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
#pragma once
#include "cthing.h"
#include "math/hashfn.h"
#include "mem/mpool.h"
CT_BEGIN_DECLS
// clang-format off
typedef enum {
CT_HS_NONE = 0,
CT_HS_CONST_KEYS = 1
} CT_HSFlags;
// clang-format on
typedef struct CT_HSEntry CT_HSEntry;
typedef int (*CT_HSIterator)(const CT_HSEntry*, void*);
typedef struct {
CT_HashFn32 hash;
int (*equiv_keys)(const void* a, const void* b, uint32_t sa, uint32_t sb);
void* (*alloc_key)(const uint32_t size, void* state);
void (*free_key)(const void* key, void* state);
void* state;
} CT_HSOps;
struct CT_HSEntry {
CT_HSEntry* next;
void* key;
uint32_t keySize;
};
typedef struct CT_Hashset {
CT_HSEntry** bins;
uint32_t binMask;
uint32_t flags;
CT_MPool pool;
CT_HSOps ops;
uint32_t size;
uint32_t collisions;
} CT_Hashset;
int ct_hs_init(CT_Hashset* s,
const CT_HSOps* ops,
size_t num,
size_t poolSize,
CT_HSFlags flags);
void ct_hs_free(CT_Hashset* s);
void* ct_hs_get(const CT_Hashset* s, const void* key, uint32_t ks);
int ct_hs_contains(const CT_Hashset* s, const void* key, uint32_t ks);
int ct_hs_assoc(CT_Hashset* s, const void* key, uint32_t ks);
int ct_hs_dissoc(CT_Hashset* s, const void* key, uint32_t ks);
int ct_hs_iterate(const CT_Hashset* s, CT_HSIterator visit, void* state);
int ct_hs_into(CT_Hashset* dest, const CT_Hashset* src);
CT_END_DECLS