-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathctl_unordered_map.h
More file actions
51 lines (42 loc) · 1.18 KB
/
Copy pathctl_unordered_map.h
File metadata and controls
51 lines (42 loc) · 1.18 KB
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
/* Same hash table as unordered_set
SPDX-License-Identifier: MIT
TODO: add pairs, to handle the extra free for key and value pairs.
search only the key. for most ops, just not insert/emplace.
*/
#ifndef T
#error "Template struct type T undefined for <ctl_unordered_map.h>"
#endif
#include "ctl.h"
#define CTL_UMAP
#define HOLD
#define uset umap
#include <./ctl_unordered_set.h>
static inline I JOIN(A, insert_or_assign)(A* self, T value) {
B* node;
if ((node = JOIN(A, find_node)(self, value))) {
FREE_VALUE(self, value);
return JOIN(I, iter)(self, node);
} else {
JOIN(A, _pre_insert_grow)(self);
return JOIN(I, iter)(self, *JOIN(A, push_cached)(self, &value));
}
}
static inline I JOIN(A, insert_or_assign_found)(A* self, T value, int* foundp) {
B* node;
if ((node = JOIN(A, find_node)(self, value))) {
FREE_VALUE(self, value);
*foundp = 1;
return JOIN(I, iter)(self, node);
} else {
JOIN(A, _pre_insert_grow)(self);
*foundp = 0;
return JOIN(I, iter)(self, *JOIN(A, push_cached)(self, &value));
}
}
#undef CTL_UMAP
#undef uset
#undef T
#undef A
#undef B
#undef I
#undef GI