hashmap_generic.h

filter: Statementstmt 76.8% 5742 / 7472 Branchbran 48.3% 3544 / 7336 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 62.7% 9286 / 14808 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/ss.xsi ↑ Summary xs/ii.xsi »
1 /*
2 * hashmap_generic.h — macro template for the type-specialized maps.
3 * Each hashmap_<variant>.h defines these before including it:
4 * HM_PREFIX / HM_NODE_TYPE / HM_MAP_TYPE names
5 * HM_KEY_IS_INT integer keys, else string
6 * HM_VALUE_IS_STR | HM_VALUE_IS_SV value kind, else integer
7 * HM_INT_TYPE / HM_INT_MIN / HM_INT_MAX key width (default int64_t)
8 * HM_HAS_COUNTERS incr/decr (int values only)
9 */
10  
11 #include <stdint.h>
12 #include <stdbool.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <time.h>
16  
17 /* ---- Macro helpers ---- */
18  
19 #define HM_PASTE2(a, b) a##_##b
20 #define HM_PASTE(a, b) HM_PASTE2(a, b)
21 #define HM_FN(name) HM_PASTE(HM_PREFIX, name)
22  
23 /* ---- Integer type defaults ---- */
24  
25 #ifndef HM_INT_TYPE
26 #define HM_INT_TYPE int64_t
27 #define HM_INT_MIN INT64_MIN
28 #define HM_INT_MAX INT64_MAX
29 #endif
30  
31 /* ---- Branch prediction ---- */
32  
33 #ifndef HM_LIKELY
34 #if defined(__GNUC__) || defined(__clang__)
35 #define HM_LIKELY(x) __builtin_expect(!!(x), 1)
36 #define HM_UNLIKELY(x) __builtin_expect(!!(x), 0)
37 #else
38 #define HM_LIKELY(x) (x)
39 #define HM_UNLIKELY(x) (x)
40 #endif
41 #endif
42  
43 /* ---- TTL timestamp helper ---- */
44  
45 /* Saturates; 0 is the no-expiry sentinel, so an exact 0 becomes 1. */
46 #ifndef HM_EXPIRY_AT_DEFINED
47 #define HM_EXPIRY_AT_DEFINED
48 1069 static inline uint32_t hm_expiry_at(uint32_t ttl) {
49 1069 uint32_t now = (uint32_t)time(NULL);
50 1069 uint32_t e = now + ttl;
51 1069 ▶ if (e < now) e = UINT32_MAX;
Branch: 1 branch
BranchTrueFalseTotal
if (e < now) e = UINT32_MAX; 2 1067 1069
52 1069 ▶ return e ? e : 1;
Branch: 1 branch
BranchTrueFalseTotal
return e ? e : 1; 1069 0 1069
53 }
54 #endif
55  
56 /* If idx has expired, expires it and returns false from the enclosing function. */
57 #ifndef HM_TTL_CHECK_EXPIRED_DEFINED
58 #define HM_TTL_CHECK_EXPIRED_DEFINED
59 #define HM_TTL_CHECK_EXPIRED(map, idx, may_compact) do { \
60 if (HM_UNLIKELY((map)->expires_at && (map)->expires_at[idx]) && \
61 (uint32_t)time(NULL) > (map)->expires_at[idx]) { \
62 HM_FN(expire_at)((map), (idx), (may_compact)); \
63 return false; \
64 } \
65 } while (0)
66 #endif
67  
68 #ifndef HM_MAYBE_COMPACT_DEFINED
69 #define HM_MAYBE_COMPACT_DEFINED
70 #define HM_MAYBE_COMPACT(map) do { \
71 if ((map)->tombstones > (map)->capacity / 4 || \
72 ((map)->size > 0 && (map)->tombstones > (map)->size && \
73 (map)->tombstones > (map)->capacity / 8)) \
74 HM_FN(compact)(map); \
75 } while (0)
76 #endif
77  
78 /* Returns fail_ret from the enclosing function on OOM. */
79 #ifndef HM_ENSURE_CAPACITY_DEFINED
80 #define HM_ENSURE_CAPACITY_DEFINED
81 #define HM_ENSURE_CAPACITY(map, fail_ret) do { \
82 if (((map)->size + (map)->tombstones) * 4 >= (map)->capacity * 3) { \
83 if ((map)->expires_at) HM_FN(reap_expired)(map); \
84 if (((map)->size + (map)->tombstones) * 4 >= (map)->capacity * 3) { \
85 if ((map)->tombstones * 2 >= (map)->size) { \
86 if (!HM_FN(compact)(map)) return fail_ret; \
87 } else { \
88 if (!HM_FN(resize)(map)) return fail_ret; \
89 } \
90 } \
91 } \
92 } while (0)
93 #endif
94  
95 /* Call before changing map state: returns fail_ret from the enclosing function on OOM. */
96 #ifndef HM_LAZY_ALLOC_EXPIRES_DEFINED
97 #define HM_LAZY_ALLOC_EXPIRES_DEFINED
98 #define HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, fail_ret) do { \
99 if (HM_UNLIKELY((entry_ttl) > 0 && !(map)->expires_at)) { \
100 (map)->expires_at = (uint32_t*)calloc((map)->capacity, sizeof(uint32_t)); \
101 if (!(map)->expires_at) return fail_ret; \
102 } \
103 } while (0)
104 #endif
105  
106 /* Assumes expires_at[slot] is already 0, as on a fresh get_or_set slot. */
107 #ifndef HM_APPLY_ENTRY_TTL_DEFINED
108 #define HM_APPLY_ENTRY_TTL_DEFINED
109 #define HM_APPLY_ENTRY_TTL(map, idx, entry_ttl) do { \
110 if ((map)->expires_at) { \
111 uint32_t _hm_ttl = (entry_ttl) > 0 ? (entry_ttl) : (map)->default_ttl; \
112 if (_hm_ttl > 0) (map)->expires_at[idx] = hm_expiry_at(_hm_ttl); \
113 } \
114 } while (0)
115 #endif
116  
117 /* ---- Constants ---- */
118  
119 #ifndef HM_INITIAL_CAPACITY
120 #define HM_INITIAL_CAPACITY 16
121 #endif
122  
123 #ifdef HM_KEY_IS_INT
124 #define HM_EMPTY_KEY HM_INT_MIN
125 #define HM_TOMBSTONE_KEY (HM_INT_MIN + 1)
126 #define HM_IS_RESERVED_KEY(k) ((k) == HM_EMPTY_KEY || (k) == HM_TOMBSTONE_KEY)
127 #endif
128  
129 /* ---- UTF-8 flag packing in uint32_t length ---- */
130  
131 #ifndef HM_UTF8_MACROS_DEFINED
132 #define HM_UTF8_MACROS_DEFINED
133 #define HM_UTF8_FLAG ((uint32_t)0x80000000U)
134 #define HM_LEN_MASK ((uint32_t)0x7FFFFFFFU)
135 #define HM_PACK_LEN(len, is_utf8) ((uint32_t)(len) | ((is_utf8) ? HM_UTF8_FLAG : 0))
136 #define HM_UNPACK_LEN(packed) ((uint32_t)((packed) & HM_LEN_MASK))
137 #define HM_UNPACK_UTF8(packed) (((packed) & HM_UTF8_FLAG) != 0)
138 #endif
139  
140 /* ---- LRU sentinel ---- */
141  
142 #ifndef HM_LRU_NONE_DEFINED
143 #define HM_LRU_NONE_DEFINED
144 #define HM_LRU_NONE UINT32_MAX
145 #endif
146  
147 /* ---- Hash functions (xxHash v0.8.3) ---- */
148  
149 #ifndef HM_HASH_FUNCTIONS_DEFINED
150 #define HM_HASH_FUNCTIONS_DEFINED
151  
152 /* perl's malloc macros need my_perl, which static inline code lacks: use the system allocator. */
153 #undef malloc
154 #undef free
155 #undef calloc
156 #undef realloc
157  
158 #define XXH_INLINE_ALL
159 #include "xxhash.h"
160  
161 /* Derived once in BOOT from PL_hash_seed. */
162 static XXH_ALIGN(XXH_SEC_ALIGN) uint8_t hm_hash_secret[XXH3_SECRET_DEFAULT_SIZE];
163  
164 4294875 static inline size_t hm_hash_int64(int64_t key) {
165 4294875 return (size_t)XXH3_64bits_withSecret(&key, sizeof(key), hm_hash_secret, sizeof(hm_hash_secret));
166 }
167  
168 1087888 static inline uint32_t hm_hash_string(const char* data, uint32_t len) {
169 1087888 return (uint32_t)XXH3_64bits_withSecret(data, len, hm_hash_secret, sizeof(hm_hash_secret));
170 }
171  
172 #endif /* HM_HASH_FUNCTIONS_DEFINED */
173  
174 /* ---- Tombstone marker for string keys ---- */
175  
176 #ifndef HM_KEY_IS_INT
177 #ifndef HM_STR_TOMBSTONE_DEFINED
178 #define HM_STR_TOMBSTONE_DEFINED
179 static char hm_str_tombstone_marker;
180 #endif
181 #define HM_STR_TOMBSTONE (&hm_str_tombstone_marker)
182 #endif
183  
184 /* ---- Node struct ---- */
185  
186 typedef struct {
187 #ifdef HM_KEY_IS_INT
188 HM_INT_TYPE key;
189 #else
190 char* key; /* NULL = empty, HM_STR_TOMBSTONE = deleted */
191 uint32_t key_len; /* high bit = UTF-8 flag */
192 uint32_t key_hash;
193 #endif
194 #ifdef HM_VALUE_IS_STR
195 char* value;
196 uint32_t val_len; /* high bit = UTF-8 flag */
197 #elif defined(HM_VALUE_IS_SV)
198 void* value; /* opaque SV* — refcounted by caller */
199 #else
200 HM_INT_TYPE value;
201 #endif
202 } HM_NODE_TYPE;
203  
204 typedef struct {
205 HM_NODE_TYPE* nodes;
206 size_t capacity;
207 size_t size;
208 size_t tombstones;
209 size_t mask;
210 /* LRU fields (active only when max_size > 0) */
211 size_t max_size;
212 uint32_t lru_head;
213 uint32_t lru_tail;
214 uint32_t* lru_prev;
215 uint32_t* lru_next;
216 uint32_t lru_skip; /* original percentage for accessor */
217 uint32_t lru_skip_ctr; /* gains 100 - lru_skip per access; promotes at 100 */
218 /* TTL fields (allocated on first TTL use) */
219 uint32_t default_ttl;
220 uint32_t* expires_at;
221 size_t iter_pos;
222 size_t drain_pos;
223 #ifdef HM_VALUE_IS_SV
224 void (*free_value_fn)(void*); /* deferred release, for single-slot paths */
225 void (*free_value_now_fn)(void*); /* immediate release, for clear/destroy */
226 bool copy_values; /* store copies instead of the caller's SV */
227 #endif
228 } HM_MAP_TYPE;
229  
230 /* ---- Slot state macros ---- */
231  
232 #ifdef HM_KEY_IS_INT
233 #define HM_SLOT_IS_EMPTY(n) ((n)->key == HM_EMPTY_KEY)
234 #define HM_SLOT_IS_TOMBSTONE(n) ((n)->key == HM_TOMBSTONE_KEY)
235 #define HM_SLOT_IS_LIVE(n) (!HM_SLOT_IS_EMPTY(n) && !HM_SLOT_IS_TOMBSTONE(n))
236 #else
237 #define HM_SLOT_IS_EMPTY(n) ((n)->key == NULL)
238 #define HM_SLOT_IS_TOMBSTONE(n) ((n)->key == HM_STR_TOMBSTONE)
239 #define HM_SLOT_IS_LIVE(n) (!HM_SLOT_IS_EMPTY(n) && !HM_SLOT_IS_TOMBSTONE(n))
240 #endif
241  
242 /* ---- Init nodes ---- */
243  
244 6790 static inline void HM_FN(init_nodes)(HM_NODE_TYPE* nodes, size_t capacity) {
245 #ifdef HM_KEY_IS_INT
246 /* Integer keys use sentinel values — must init per-element */
247 size_t i;
248 7736677 ▶ for (i = 0; i < capacity; i++) {
Branch: 9 branches
BranchTrueFalseTotal
for (i = 0; i < capacity; i++) { 729660 886 730546
for (i = 0; i < capacity; i++) { 264639 359 264998
for (i = 0; i < capacity; i++) { 527227 424 527651
for (i = 0; i < capacity; i++) { 706105 266 706371
for (i = 0; i < capacity; i++) { 709720 331 710051
for (i = 0; i < capacity; i++) { 2710107 1309 2711416
for (i = 0; i < capacity; i++) { 1095257 294 1095551
for (i = 0; i < capacity; i++) { 443365 164 443529
for (i = 0; i < capacity; i++) { 546281 283 546564
249 7732361 nodes[i].key = HM_EMPTY_KEY;
250 #ifdef HM_VALUE_IS_STR
251 1859190 nodes[i].value = NULL;
252 1859190 nodes[i].val_len = 0;
253 #elif defined(HM_VALUE_IS_SV)
254 1521526 nodes[i].value = NULL;
255 #else
256 4351645 nodes[i].value = 0;
257 #endif
258 }
259 #else
260 /* String keys: NULL=empty, all-zero works for pointers and lengths */
261 2474 memset(nodes, 0, capacity * sizeof(HM_NODE_TYPE));
262 #endif
263 6790 }
264  
265 /* ---- Free resources for a single node ---- */
266  
267 1357886 static inline void HM_FN(free_node_impl)(HM_MAP_TYPE* map, HM_NODE_TYPE* node, bool now) {
268 (void)map;
269 #ifndef HM_KEY_IS_INT
270 411671 ▶ if (node->key != NULL && node->key != HM_STR_TOMBSTONE) {
Branch: 10 branches
BranchTrueFalseTotal
if (node->key != NULL && node->key != HM_STR_TOMBSTONE) { 82481 0 82481
if (node->key != NULL && node->key != HM_STR_TOMBSTONE) { 82481 0 82481
if (node->key != NULL && node->key != HM_STR_TOMBSTONE) { 80236 0 80236
if (node->key != NULL && node->key != HM_STR_TOMBSTONE) { 80236 0 80236
if (node->key != NULL && node->key != HM_STR_TOMBSTONE) { 88526 0 88526
if (node->key != NULL && node->key != HM_STR_TOMBSTONE) { 88526 0 88526
if (node->key != NULL && node->key != HM_STR_TOMBSTONE) { 80292 0 80292
if (node->key != NULL && node->key != HM_STR_TOMBSTONE) { 80292 0 80292
if (node->key != NULL && node->key != HM_STR_TOMBSTONE) { 80136 0 80136
if (node->key != NULL && node->key != HM_STR_TOMBSTONE) { 80136 0 80136
271 411671 free(node->key);
272 411671 node->key = NULL;
273 }
274 #endif
275 #ifdef HM_VALUE_IS_STR
276 310294 ▶ if (node->value != NULL) {
Branch: 4 branches
BranchTrueFalseTotal
if (node->value != NULL) { 80417 1 80418
if (node->value != NULL) { 88523 3 88526
if (node->value != NULL) { 81034 1 81035
if (node->value != NULL) { 60314 1 60315
277 310288 free(node->value);
278 310288 node->value = NULL;
279 }
280 #elif defined(HM_VALUE_IS_SV)
281 252948 ▶ if (node->value != NULL) {
Branch: 4 branches
BranchTrueFalseTotal
if (node->value != NULL) { 82453 28 82481
if (node->value != NULL) { 88907 6 88913
if (node->value != NULL) { 30746 1 30747
if (node->value != NULL) { 50806 1 50807
282 252912 ▶ void (*rel)(void*) = now ? map->free_value_now_fn : map->free_value_fn;
Branch: 4 branches
BranchTrueFalseTotal
void (*rel)(void*) = now ? map->free_value_now_fn : map->free_value_fn; 1417 81036 82453
void (*rel)(void*) = now ? map->free_value_now_fn : map->free_value_fn; 7489 81418 88907
void (*rel)(void*) = now ? map->free_value_now_fn : map->free_value_fn; 556 30190 30746
void (*rel)(void*) = now ? map->free_value_now_fn : map->free_value_fn; 616 50190 50806
283 252912 ▶ if (rel) rel(node->value);
Branch: 4 branches
BranchTrueFalseTotal
if (rel) rel(node->value); 82453 0 82453
if (rel) rel(node->value); 88907 0 88907
if (rel) rel(node->value); 30746 0 30746
if (rel) rel(node->value); 50806 0 50806
284 252912 node->value = NULL;
285 }
286 #endif
287 (void)node; (void)now;
288 1357886 }
289  
290 #define HM_FREE_NODE(map, node) HM_FN(free_node_impl)((map), (node), false)
291 #define HM_FREE_NODE_NOW(map, node) HM_FN(free_node_impl)((map), (node), true)
292  
293 /* ---- LRU helpers ---- */
294  
295 45477 static inline void HM_FN(lru_unlink)(HM_MAP_TYPE* map, uint32_t idx) {
296 45477 uint32_t p = map->lru_prev[idx];
297 45477 uint32_t n = map->lru_next[idx];
298 45477 ▶ if (p != HM_LRU_NONE) map->lru_next[p] = n;
Branch: 14 branches
BranchTrueFalseTotal
if (p != HM_LRU_NONE) map->lru_next[p] = n; 589 4 593
if (p != HM_LRU_NONE) map->lru_next[p] = n; 780 8 788
if (p != HM_LRU_NONE) map->lru_next[p] = n; 249 3 252
if (p != HM_LRU_NONE) map->lru_next[p] = n; 249 3 252
if (p != HM_LRU_NONE) map->lru_next[p] = n; 1 1 2
if (p != HM_LRU_NONE) map->lru_next[p] = n; 181 0 181
if (p != HM_LRU_NONE) map->lru_next[p] = n; 352 0 352
if (p != HM_LRU_NONE) map->lru_next[p] = n; 3 1 4
if (p != HM_LRU_NONE) map->lru_next[p] = n; 181 0 181
if (p != HM_LRU_NONE) map->lru_next[p] = n; 42678 7 42685
if (p != HM_LRU_NONE) map->lru_next[p] = n; 1 0 1
if (p != HM_LRU_NONE) map->lru_next[p] = n; 3 1 4
if (p != HM_LRU_NONE) map->lru_next[p] = n; 181 0 181
if (p != HM_LRU_NONE) map->lru_next[p] = n; 1 0 1
299 0 else map->lru_head = n;
300 45477 ▶ if (n != HM_LRU_NONE) map->lru_prev[n] = p;
Branch: 14 branches
BranchTrueFalseTotal
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 66 527 593
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 66 722 788
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 63 189 252
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 63 189 252
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 0 2 2
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 0 181 181
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 0 352 352
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 1 3 4
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 0 181 181
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 24 42661 42685
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 0 1 1
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 1 3 4
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 0 181 181
if (n != HM_LRU_NONE) map->lru_prev[n] = p; 0 1 1
301 45193 else map->lru_tail = p;
302 45477 map->lru_prev[idx] = HM_LRU_NONE;
303 45477 map->lru_next[idx] = HM_LRU_NONE;
304 45477 }
305  
306 46537 static inline void HM_FN(lru_push_front)(HM_MAP_TYPE* map, uint32_t idx) {
307 46537 map->lru_prev[idx] = HM_LRU_NONE;
308 46537 map->lru_next[idx] = map->lru_head;
309 46537 ▶ if (map->lru_head != HM_LRU_NONE)
Branch: 14 branches
BranchTrueFalseTotal
if (map->lru_head != HM_LRU_NONE) 669 10 679
if (map->lru_head != HM_LRU_NONE) 825 12 837
if (map->lru_head != HM_LRU_NONE) 273 5 278
if (map->lru_head != HM_LRU_NONE) 273 5 278
if (map->lru_head != HM_LRU_NONE) 2 2 4
if (map->lru_head != HM_LRU_NONE) 200 3 203
if (map->lru_head != HM_LRU_NONE) 419 8 427
if (map->lru_head != HM_LRU_NONE) 5 2 7
if (map->lru_head != HM_LRU_NONE) 200 3 203
if (map->lru_head != HM_LRU_NONE) 43350 53 43403
if (map->lru_head != HM_LRU_NONE) 3 1 4
if (map->lru_head != HM_LRU_NONE) 5 2 7
if (map->lru_head != HM_LRU_NONE) 200 3 203
if (map->lru_head != HM_LRU_NONE) 3 1 4
310 46427 map->lru_prev[map->lru_head] = idx;
311 else
312 110 map->lru_tail = idx;
313 46537 map->lru_head = idx;
314 46537 }
315  
316 0 static inline void HM_FN(lru_promote)(HM_MAP_TYPE* map, uint32_t idx) {
317 0 ▶ if (map->lru_head == idx) return;
Branch: 14 branches
BranchTrueFalseTotal
if (map->lru_head == idx) return; 2 0 2
if (map->lru_head == idx) return; 3 2 5
if (map->lru_head == idx) return; 2 0 2
if (map->lru_head == idx) return; 2 0 2
if (map->lru_head == idx) return; 0 0 0
if (map->lru_head == idx) return; 0 0 0
if (map->lru_head == idx) return; 3 0 3
if (map->lru_head == idx) return; 0 2 2
if (map->lru_head == idx) return; 1 0 1
if (map->lru_head == idx) return; 59 161 220
if (map->lru_head == idx) return; 0 0 0
if (map->lru_head == idx) return; 0 2 2
if (map->lru_head == idx) return; 0 0 0
if (map->lru_head == idx) return; 0 0 0
318 0 ▶ if (map->lru_skip && idx != map->lru_tail) {
Branch: 28 branches
BranchTrueFalseTotal
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 2 2
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 2 2
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 35 126 161
if (map->lru_skip && idx != map->lru_tail) { 34 1 35
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 2 2
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
if (map->lru_skip && idx != map->lru_tail) { 0 0 0
319 0 map->lru_skip_ctr += 100 - map->lru_skip;
320 0 ▶ if (map->lru_skip_ctr < 100) return;
Branch: 14 branches
BranchTrueFalseTotal
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 32 2 34
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
if (map->lru_skip_ctr < 100) return; 0 0 0
321 0 map->lru_skip_ctr -= 100;
322 }
323 0 HM_FN(lru_unlink)(map, idx);
324 0 HM_FN(lru_push_front)(map, idx);
325 }
326  
327 1337786 static void HM_FN(tombstone_at)(HM_MAP_TYPE* map, size_t index) {
328 1337786 HM_FREE_NODE(map, &map->nodes[index]);
329 #ifdef HM_KEY_IS_INT
330 935575 map->nodes[index].key = HM_TOMBSTONE_KEY;
331 #else
332 402211 map->nodes[index].key = HM_STR_TOMBSTONE;
333 402211 map->nodes[index].key_len = 0;
334 402211 map->nodes[index].key_hash = 0;
335 #endif
336 #ifdef HM_VALUE_IS_STR
337 301773 map->nodes[index].val_len = 0;
338 #endif
339 1337786 ▶ if (map->expires_at) map->expires_at[index] = 0;
Branch: 14 branches
BranchTrueFalseTotal
if (map->expires_at) map->expires_at[index] = 0; 165 80899 81064
if (map->expires_at) map->expires_at[index] = 0; 5 81419 81424
if (map->expires_at) map->expires_at[index] = 0; 4 30187 30191
if (map->expires_at) map->expires_at[index] = 0; 4 50187 50191
if (map->expires_at) map->expires_at[index] = 0; 1 80013 80014
if (map->expires_at) map->expires_at[index] = 0; 0 80187 80187
if (map->expires_at) map->expires_at[index] = 0; 168 80937 81105
if (map->expires_at) map->expires_at[index] = 0; 1 80013 80014
if (map->expires_at) map->expires_at[index] = 0; 1 80295 80296
if (map->expires_at) map->expires_at[index] = 0; 56 322824 322880
if (map->expires_at) map->expires_at[index] = 0; 1 150209 150210
if (map->expires_at) map->expires_at[index] = 0; 2 80012 80014
if (map->expires_at) map->expires_at[index] = 0; 0 60185 60185
if (map->expires_at) map->expires_at[index] = 0; 1 80010 80011
340 1337786 map->size--;
341 1337786 map->tombstones++;
342 1337786 }
343  
344 45027 static void HM_FN(lru_evict_one)(HM_MAP_TYPE* map) {
345 45027 uint32_t victim = map->lru_tail;
346 45027 ▶ if (victim == HM_LRU_NONE) return;
Branch: 14 branches
BranchTrueFalseTotal
if (victim == HM_LRU_NONE) return; 0 522 522
if (victim == HM_LRU_NONE) return; 0 708 708
if (victim == HM_LRU_NONE) return; 0 182 182
if (victim == HM_LRU_NONE) return; 0 182 182
if (victim == HM_LRU_NONE) return; 0 1 1
if (victim == HM_LRU_NONE) return; 0 181 181
if (victim == HM_LRU_NONE) return; 0 351 351
if (victim == HM_LRU_NONE) return; 0 1 1
if (victim == HM_LRU_NONE) return; 0 181 181
if (victim == HM_LRU_NONE) return; 0 42534 42534
if (victim == HM_LRU_NONE) return; 0 1 1
if (victim == HM_LRU_NONE) return; 0 1 1
if (victim == HM_LRU_NONE) return; 0 181 181
if (victim == HM_LRU_NONE) return; 0 1 1
347 45027 HM_FN(lru_unlink)(map, victim);
348 45027 HM_FN(tombstone_at)(map, (size_t)victim);
349 }
350  
351 static bool HM_FN(compact)(HM_MAP_TYPE* map);
352  
353 /* may_compact is false on read paths so that a lookup never resets an each() in progress. */
354 0 static void HM_FN(expire_at)(HM_MAP_TYPE* map, size_t index, bool may_compact) {
355 0 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index);
Branch: 14 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 3 3
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 3 3
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 3 3
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 4 18 22
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
356 0 HM_FN(tombstone_at)(map, index);
357 0 ▶ if (may_compact) HM_MAYBE_COMPACT(map);
Branch: 70 branches
BranchTrueFalseTotal
if (may_compact) HM_MAYBE_COMPACT(map); 1 2 3
if (may_compact) HM_MAYBE_COMPACT(map); 1 0 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 1 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 1 2 3
if (may_compact) HM_MAYBE_COMPACT(map); 1 0 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 1 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 1 1 2
if (may_compact) HM_MAYBE_COMPACT(map); 1 0 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 1 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 1 1 2
if (may_compact) HM_MAYBE_COMPACT(map); 1 0 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 1 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 1 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 3 3
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 1 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 1 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 7 15 22
if (may_compact) HM_MAYBE_COMPACT(map); 7 0 7
if (may_compact) HM_MAYBE_COMPACT(map); 2 5 7
if (may_compact) HM_MAYBE_COMPACT(map); 1 1 2
if (may_compact) HM_MAYBE_COMPACT(map); 0 1 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 1 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 2 2
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 1 1
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
if (may_compact) HM_MAYBE_COMPACT(map); 0 0 0
358 0 }
359  
360 /* ---- Create / Destroy ---- */
361  
362 751 static HM_MAP_TYPE* HM_FN(create)(size_t max_size, uint32_t default_ttl, uint32_t lru_skip) {
363 751 HM_MAP_TYPE* map = (HM_MAP_TYPE*)malloc(sizeof(HM_MAP_TYPE));
364 751 ▶ if (!map) return NULL;
Branch: 14 branches
BranchTrueFalseTotal
if (!map) return NULL; 0 76 76
if (!map) return NULL; 0 78 78
if (!map) return NULL; 0 30 30
if (!map) return NULL; 0 30 30
if (!map) return NULL; 0 26 26
if (!map) return NULL; 0 15 15
if (!map) return NULL; 0 106 106
if (!map) return NULL; 0 41 41
if (!map) return NULL; 0 39 39
if (!map) return NULL; 0 206 206
if (!map) return NULL; 0 34 34
if (!map) return NULL; 0 26 26
if (!map) return NULL; 0 16 16
if (!map) return NULL; 0 28 28
365  
366 751 map->capacity = HM_INITIAL_CAPACITY;
367 751 map->mask = HM_INITIAL_CAPACITY - 1;
368 751 map->size = 0;
369 751 map->tombstones = 0;
370 751 map->max_size = max_size;
371 751 map->default_ttl = default_ttl;
372 751 map->lru_skip = (lru_skip > 99) ? 99 : lru_skip;
373 751 map->lru_skip_ctr = 0;
374 751 map->lru_head = HM_LRU_NONE;
375 751 map->lru_tail = HM_LRU_NONE;
376 751 map->lru_prev = NULL;
377 751 map->lru_next = NULL;
378 751 map->iter_pos = 0;
379 751 map->drain_pos = 0;
380 #ifdef HM_VALUE_IS_SV
381 214 map->free_value_fn = NULL;
382 214 map->free_value_now_fn = NULL;
383 214 map->copy_values = false;
384 #endif
385 751 map->expires_at = NULL;
386  
387 751 map->nodes = (HM_NODE_TYPE*)malloc(map->capacity * sizeof(HM_NODE_TYPE));
388 751 ▶ if (!map->nodes) { free(map); return NULL; }
Branch: 14 branches
BranchTrueFalseTotal
if (!map->nodes) { free(map); return NULL; } 0 76 76
if (!map->nodes) { free(map); return NULL; } 0 78 78
if (!map->nodes) { free(map); return NULL; } 0 30 30
if (!map->nodes) { free(map); return NULL; } 0 30 30
if (!map->nodes) { free(map); return NULL; } 0 26 26
if (!map->nodes) { free(map); return NULL; } 0 15 15
if (!map->nodes) { free(map); return NULL; } 0 106 106
if (!map->nodes) { free(map); return NULL; } 0 41 41
if (!map->nodes) { free(map); return NULL; } 0 39 39
if (!map->nodes) { free(map); return NULL; } 0 206 206
if (!map->nodes) { free(map); return NULL; } 0 34 34
if (!map->nodes) { free(map); return NULL; } 0 26 26
if (!map->nodes) { free(map); return NULL; } 0 16 16
if (!map->nodes) { free(map); return NULL; } 0 28 28
389 751 HM_FN(init_nodes)(map->nodes, map->capacity);
390  
391 751 ▶ if (max_size > 0) {
Branch: 14 branches
BranchTrueFalseTotal
if (max_size > 0) { 12 64 76
if (max_size > 0) { 11 67 78
if (max_size > 0) { 5 25 30
if (max_size > 0) { 5 25 30
if (max_size > 0) { 2 24 26
if (max_size > 0) { 3 12 15
if (max_size > 0) { 8 98 106
if (max_size > 0) { 2 39 41
if (max_size > 0) { 3 36 39
if (max_size > 0) { 61 145 206
if (max_size > 0) { 1 33 34
if (max_size > 0) { 2 24 26
if (max_size > 0) { 3 13 16
if (max_size > 0) { 1 27 28
392 119 map->lru_prev = (uint32_t*)malloc(map->capacity * sizeof(uint32_t));
393 119 map->lru_next = (uint32_t*)malloc(map->capacity * sizeof(uint32_t));
394 119 ▶ if (!map->lru_prev || !map->lru_next) {
Branch: 28 branches
BranchTrueFalseTotal
if (!map->lru_prev || !map->lru_next) { 12 0 12
if (!map->lru_prev || !map->lru_next) { 0 12 12
if (!map->lru_prev || !map->lru_next) { 11 0 11
if (!map->lru_prev || !map->lru_next) { 0 11 11
if (!map->lru_prev || !map->lru_next) { 5 0 5
if (!map->lru_prev || !map->lru_next) { 0 5 5
if (!map->lru_prev || !map->lru_next) { 5 0 5
if (!map->lru_prev || !map->lru_next) { 0 5 5
if (!map->lru_prev || !map->lru_next) { 2 0 2
if (!map->lru_prev || !map->lru_next) { 0 2 2
if (!map->lru_prev || !map->lru_next) { 3 0 3
if (!map->lru_prev || !map->lru_next) { 0 3 3
if (!map->lru_prev || !map->lru_next) { 8 0 8
if (!map->lru_prev || !map->lru_next) { 0 8 8
if (!map->lru_prev || !map->lru_next) { 2 0 2
if (!map->lru_prev || !map->lru_next) { 0 2 2
if (!map->lru_prev || !map->lru_next) { 3 0 3
if (!map->lru_prev || !map->lru_next) { 0 3 3
if (!map->lru_prev || !map->lru_next) { 61 0 61
if (!map->lru_prev || !map->lru_next) { 0 61 61
if (!map->lru_prev || !map->lru_next) { 1 0 1
if (!map->lru_prev || !map->lru_next) { 0 1 1
if (!map->lru_prev || !map->lru_next) { 2 0 2
if (!map->lru_prev || !map->lru_next) { 0 2 2
if (!map->lru_prev || !map->lru_next) { 3 0 3
if (!map->lru_prev || !map->lru_next) { 0 3 3
if (!map->lru_prev || !map->lru_next) { 1 0 1
if (!map->lru_prev || !map->lru_next) { 0 1 1
395 0 free(map->lru_prev); free(map->lru_next);
396 0 free(map->nodes); free(map);
397 0 return NULL;
398 }
399 119 memset(map->lru_prev, 0xFF, map->capacity * sizeof(uint32_t));
400 119 memset(map->lru_next, 0xFF, map->capacity * sizeof(uint32_t));
401 }
402  
403 751 ▶ if (default_ttl > 0) {
Branch: 14 branches
BranchTrueFalseTotal
if (default_ttl > 0) { 5 71 76
if (default_ttl > 0) { 4 74 78
if (default_ttl > 0) { 2 28 30
if (default_ttl > 0) { 2 28 30
if (default_ttl > 0) { 0 26 26
if (default_ttl > 0) { 0 15 15
if (default_ttl > 0) { 9 97 106
if (default_ttl > 0) { 1 40 41
if (default_ttl > 0) { 1 38 39
if (default_ttl > 0) { 35 171 206
if (default_ttl > 0) { 0 34 34
if (default_ttl > 0) { 1 25 26
if (default_ttl > 0) { 0 16 16
if (default_ttl > 0) { 1 27 28
404 0 map->expires_at = (uint32_t*)calloc(map->capacity, sizeof(uint32_t));
405 0 ▶ if (!map->expires_at) {
Branch: 14 branches
BranchTrueFalseTotal
if (!map->expires_at) { 0 5 5
if (!map->expires_at) { 0 4 4
if (!map->expires_at) { 0 2 2
if (!map->expires_at) { 0 2 2
if (!map->expires_at) { 0 0 0
if (!map->expires_at) { 0 0 0
if (!map->expires_at) { 0 9 9
if (!map->expires_at) { 0 1 1
if (!map->expires_at) { 0 1 1
if (!map->expires_at) { 0 35 35
if (!map->expires_at) { 0 0 0
if (!map->expires_at) { 0 1 1
if (!map->expires_at) { 0 0 0
if (!map->expires_at) { 0 1 1
406 0 free(map->lru_prev); free(map->lru_next);
407 0 free(map->nodes); free(map);
408 0 return NULL;
409 }
410 }
411  
412 751 return map;
413 }
414  
415 777 static void HM_FN(destroy)(HM_MAP_TYPE* map) {
416 777 ▶ if (!map) return;
Branch: 14 branches
BranchTrueFalseTotal
if (!map) return; 0 80 80
if (!map) return; 0 84 84
if (!map) return; 0 34 34
if (!map) return; 0 34 34
if (!map) return; 0 26 26
if (!map) return; 0 15 15
if (!map) return; 0 108 108
if (!map) return; 0 41 41
if (!map) return; 0 39 39
if (!map) return; 0 211 211
if (!map) return; 0 35 35
if (!map) return; 0 26 26
if (!map) return; 0 16 16
if (!map) return; 0 28 28
417 #if !defined(HM_KEY_IS_INT) || defined(HM_VALUE_IS_STR) || defined(HM_VALUE_IS_SV)
418 {
419 size_t i;
420 1500071 ▶ for (i = 0; i < map->capacity; i++) {
Branch: 11 branches
BranchTrueFalseTotal
for (i = 0; i < map->capacity; i++) { 151840 80 151920
for (i = 0; i < map->capacity; i++) { 161008 84 161092
for (i = 0; i < map->capacity; i++) { 67024 34 67058
for (i = 0; i < map->capacity; i++) { 132752 34 132786
for (i = 0; i < map->capacity; i++) { 148320 26 148346
for (i = 0; i < map->capacity; i++) { 148176 15 148191
for (i = 0; i < map->capacity; i++) { 161488 108 161596
for (i = 0; i < map->capacity; i++) { 148592 41 148633
for (i = 0; i < map->capacity; i++) { 149904 39 149943
for (i = 0; i < map->capacity; i++) { 148064 26 148090
for (i = 0; i < map->capacity; i++) { 82400 16 82416
421 1499568 ▶ if (HM_SLOT_IS_LIVE(&map->nodes[i])) {
Branch: 22 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 10497 141343 151840
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 891 9606 10497
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 16860 144148 161008
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 6896 9964 16860
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 7096 59928 67024
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 273 6823 7096
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 8904 123848 132752
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 273 8631 8904
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 9551 138769 148320
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 24 9527 9551
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 9562 138614 148176
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 32 9530 9562
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 16754 144734 161488
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 6750 10004 16754
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 9606 138986 148592
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 80 9526 9606
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 10087 139817 149904
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 541 9546 10087
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 9550 138514 148064
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 24 9526 9550
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 7752 74648 82400
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 31 7721 7752
422 15815 HM_FREE_NODE_NOW(map, &map->nodes[i]);
423 }
424 }
425 }
426 #endif
427 777 free(map->lru_prev);
428 777 free(map->lru_next);
429 777 free(map->expires_at);
430 777 free(map->nodes);
431 777 free(map);
432 }
433  
434 /* ---- clear: remove all entries without destroying the map ---- */
435  
436 80 static void HM_FN(clear)(HM_MAP_TYPE* map) {
437 80 ▶ if (!map) return;
Branch: 14 branches
BranchTrueFalseTotal
if (!map) return; 0 11 11
if (!map) return; 0 14 14
if (!map) return; 0 7 7
if (!map) return; 0 7 7
if (!map) return; 0 2 2
if (!map) return; 0 3 3
if (!map) return; 0 11 11
if (!map) return; 0 2 2
if (!map) return; 0 2 2
if (!map) return; 0 10 10
if (!map) return; 0 3 3
if (!map) return; 0 2 2
if (!map) return; 0 3 3
if (!map) return; 0 3 3
438 /* A value's DESTROY may write to the map: keep exact accounting at every
439 step and, like hv_clear, sweep again until nothing is left. */
440 80 map->iter_pos = 0;
441 80 map->drain_pos = 0;
442 do {
443 size_t i;
444 #ifdef HM_VALUE_IS_SV
445 /* Sweep backwards from an empty slot, so deletions end probe chains. */
446 122 ▶ for (i = 0; i < map->capacity && !HM_SLOT_IS_EMPTY(&map->nodes[i]); i++) {}
Branch: 8 branches
BranchTrueFalseTotal
for (i = 0; i < map->capacity && !HM_SLOT_IS_EMPTY(&map->nodes[i]); i++) {} 27 0 27
for (i = 0; i < map->capacity && !HM_SLOT_IS_EMPTY(&map->nodes[i]); i++) {} 16 11 27
for (i = 0; i < map->capacity && !HM_SLOT_IS_EMPTY(&map->nodes[i]); i++) {} 41 0 41
for (i = 0; i < map->capacity && !HM_SLOT_IS_EMPTY(&map->nodes[i]); i++) {} 26 15 41
for (i = 0; i < map->capacity && !HM_SLOT_IS_EMPTY(&map->nodes[i]); i++) {} 35 0 35
for (i = 0; i < map->capacity && !HM_SLOT_IS_EMPTY(&map->nodes[i]); i++) {} 28 7 35
for (i = 0; i < map->capacity && !HM_SLOT_IS_EMPTY(&map->nodes[i]); i++) {} 19 0 19
for (i = 0; i < map->capacity && !HM_SLOT_IS_EMPTY(&map->nodes[i]); i++) {} 12 7 19
447 40 size_t left = map->capacity;
448 4152 ▶ while (left--) {
Branch: 4 branches
BranchTrueFalseTotal
while (left--) { 1328 11 1339
while (left--) { 1408 15 1423
while (left--) { 592 7 599
while (left--) { 784 7 791
449 4112 ▶ if (i == 0) i = map->capacity;
Branch: 4 branches
BranchTrueFalseTotal
if (i == 0) i = map->capacity; 11 1317 1328
if (i == 0) i = map->capacity; 15 1393 1408
if (i == 0) i = map->capacity; 7 585 592
if (i == 0) i = map->capacity; 7 777 784
450 4112 i--;
451 #else
452 6841 ▶ for (i = 0; i < map->capacity; i++) {
Branch: 10 branches
BranchTrueFalseTotal
for (i = 0; i < map->capacity; i++) { 512 2 514
for (i = 0; i < map->capacity; i++) { 528 3 531
for (i = 0; i < map->capacity; i++) { 1808 11 1819
for (i = 0; i < map->capacity; i++) { 512 2 514
for (i = 0; i < map->capacity; i++) { 512 2 514
for (i = 0; i < map->capacity; i++) { 1344 10 1354
for (i = 0; i < map->capacity; i++) { 528 3 531
for (i = 0; i < map->capacity; i++) { 256 2 258
for (i = 0; i < map->capacity; i++) { 272 3 275
for (i = 0; i < map->capacity; i++) { 528 3 531
453 #endif
454 15197 ▶ if (HM_SLOT_IS_LIVE(&map->nodes[i])) {
Branch: 28 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 556 772 1328
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 526 30 556
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 620 788 1408
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 593 27 620
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 287 305 592
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 283 4 287
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 347 437 784
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 343 4 347
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 200 312 512
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 198 2 200
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 201 327 528
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 199 2 201
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 701 1107 1808
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 671 30 701
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 200 312 512
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 198 2 200
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 200 312 512
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 198 2 200
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 507 837 1344
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 479 28 507
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 201 327 528
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 201 0 201
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 100 156 256
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 98 2 100
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 101 171 272
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 99 2 101
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 201 327 528
if (HM_SLOT_IS_LIVE(&map->nodes[i])) { 199 2 201
455 4285 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i);
Branch: 14 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 70 456 526
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 74 519 593
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 70 213 283
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 70 273 343
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 0 198 198
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 0 199 199
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 0 671 671
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 0 198 198
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 0 198 198
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 2 477 479
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 0 201 201
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 0 98 98
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 0 99 99
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)i); 0 199 199
456 4285 ▶ if (map->expires_at) map->expires_at[i] = 0;
Branch: 14 branches
BranchTrueFalseTotal
if (map->expires_at) map->expires_at[i] = 0; 105 421 526
if (map->expires_at) map->expires_at[i] = 0; 304 289 593
if (map->expires_at) map->expires_at[i] = 0; 104 179 283
if (map->expires_at) map->expires_at[i] = 0; 104 239 343
if (map->expires_at) map->expires_at[i] = 0; 0 198 198
if (map->expires_at) map->expires_at[i] = 0; 0 199 199
if (map->expires_at) map->expires_at[i] = 0; 200 471 671
if (map->expires_at) map->expires_at[i] = 0; 0 198 198
if (map->expires_at) map->expires_at[i] = 0; 0 198 198
if (map->expires_at) map->expires_at[i] = 0; 101 378 479
if (map->expires_at) map->expires_at[i] = 0; 0 201 201
if (map->expires_at) map->expires_at[i] = 0; 0 98 98
if (map->expires_at) map->expires_at[i] = 0; 0 99 99
if (map->expires_at) map->expires_at[i] = 0; 0 199 199
457 4285 HM_NODE_TYPE dead = map->nodes[i];
458 4285 HM_FN(init_nodes)(&map->nodes[i], 1);
459 #ifdef HM_VALUE_IS_SV
460 1745 ▶ if (!HM_SLOT_IS_EMPTY(&map->nodes[(i + 1) & map->mask])) {
Branch: 4 branches
BranchTrueFalseTotal
if (!HM_SLOT_IS_EMPTY(&map->nodes[(i + 1) & map->mask])) { 0 526 526
if (!HM_SLOT_IS_EMPTY(&map->nodes[(i + 1) & map->mask])) { 14 579 593
if (!HM_SLOT_IS_EMPTY(&map->nodes[(i + 1) & map->mask])) { 0 283 283
if (!HM_SLOT_IS_EMPTY(&map->nodes[(i + 1) & map->mask])) { 0 343 343
461 #ifdef HM_KEY_IS_INT
462 0 map->nodes[i].key = HM_TOMBSTONE_KEY;
463 #else
464 0 map->nodes[i].key = HM_STR_TOMBSTONE;
465 #endif
466 0 map->tombstones++;
467 }
468 #endif
469 4285 ▶ if (map->size) map->size--;
Branch: 14 branches
BranchTrueFalseTotal
if (map->size) map->size--; 526 0 526
if (map->size) map->size--; 593 0 593
if (map->size) map->size--; 283 0 283
if (map->size) map->size--; 343 0 343
if (map->size) map->size--; 198 0 198
if (map->size) map->size--; 199 0 199
if (map->size) map->size--; 671 0 671
if (map->size) map->size--; 198 0 198
if (map->size) map->size--; 198 0 198
if (map->size) map->size--; 479 0 479
if (map->size) map->size--; 201 0 201
if (map->size) map->size--; 98 0 98
if (map->size) map->size--; 99 0 99
if (map->size) map->size--; 199 0 199
470 4285 HM_FREE_NODE_NOW(map, &dead);
471 6627 ▶ } else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])
Branch: 14 branches
BranchTrueFalseTotal
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 30 772 802
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 27 788 815
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 4 305 309
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 4 437 441
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 2 312 314
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 2 327 329
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 30 1107 1137
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 2 312 314
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 2 312 314
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 28 837 865
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 0 327 327
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 2 156 158
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 2 171 173
} else if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i]) 2 327 329
472 #ifdef HM_VALUE_IS_SV
473 65 ▶ && HM_SLOT_IS_EMPTY(&map->nodes[(i + 1) & map->mask])
Branch: 4 branches
BranchTrueFalseTotal
&& HM_SLOT_IS_EMPTY(&map->nodes[(i + 1) & map->mask]) 30 0 30
&& HM_SLOT_IS_EMPTY(&map->nodes[(i + 1) & map->mask]) 27 0 27
&& HM_SLOT_IS_EMPTY(&map->nodes[(i + 1) & map->mask]) 4 0 4
&& HM_SLOT_IS_EMPTY(&map->nodes[(i + 1) & map->mask]) 4 0 4
474 #endif
475 ) {
476 0 HM_FN(init_nodes)(&map->nodes[i], 1);
477 0 ▶ if (map->tombstones) map->tombstones--;
Branch: 14 branches
BranchTrueFalseTotal
if (map->tombstones) map->tombstones--; 30 0 30
if (map->tombstones) map->tombstones--; 27 0 27
if (map->tombstones) map->tombstones--; 4 0 4
if (map->tombstones) map->tombstones--; 4 0 4
if (map->tombstones) map->tombstones--; 2 0 2
if (map->tombstones) map->tombstones--; 2 0 2
if (map->tombstones) map->tombstones--; 30 0 30
if (map->tombstones) map->tombstones--; 2 0 2
if (map->tombstones) map->tombstones--; 2 0 2
if (map->tombstones) map->tombstones--; 28 0 28
if (map->tombstones) map->tombstones--; 0 0 0
if (map->tombstones) map->tombstones--; 2 0 2
if (map->tombstones) map->tombstones--; 2 0 2
if (map->tombstones) map->tombstones--; 2 0 2
478 }
479 }
480 81 ▶ } while (map->size);
Branch: 14 branches
BranchTrueFalseTotal
} while (map->size); 0 11 11
} while (map->size); 1 14 15
} while (map->size); 0 7 7
} while (map->size); 0 7 7
} while (map->size); 0 2 2
} while (map->size); 0 3 3
} while (map->size); 0 11 11
} while (map->size); 0 2 2
} while (map->size); 0 2 2
} while (map->size); 0 10 10
} while (map->size); 0 3 3
} while (map->size); 0 2 2
} while (map->size); 0 3 3
} while (map->size); 0 3 3
481 #ifdef HM_VALUE_IS_SV
482 39 ▶ if (map->tombstones) HM_FN(init_nodes)(map->nodes, map->capacity);
Branch: 4 branches
BranchTrueFalseTotal
if (map->tombstones) HM_FN(init_nodes)(map->nodes, map->capacity); 0 11 11
if (map->tombstones) HM_FN(init_nodes)(map->nodes, map->capacity); 0 14 14
if (map->tombstones) HM_FN(init_nodes)(map->nodes, map->capacity); 0 7 7
if (map->tombstones) HM_FN(init_nodes)(map->nodes, map->capacity); 0 7 7
483 39 map->tombstones = 0;
484 39 map->iter_pos = 0;
485 39 map->drain_pos = 0;
486 #endif
487 }
488  
489 /* ---- reap_expired / purge ---- */
490  
491 /* Must not compact: the capacity check that calls it decides between compacting and growing. */
492 0 static void HM_FN(reap_expired)(HM_MAP_TYPE* map) {
493 0 ▶ if (!map || !map->expires_at) return;
Branch: 28 branches
BranchTrueFalseTotal
if (!map || !map->expires_at) return; 6 0 6
if (!map || !map->expires_at) return; 0 6 6
if (!map || !map->expires_at) return; 12 0 12
if (!map || !map->expires_at) return; 0 12 12
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 19 0 19
if (!map || !map->expires_at) return; 0 19 19
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 9 0 9
if (!map || !map->expires_at) return; 0 9 9
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
494 0 uint32_t now = (uint32_t)time(NULL);
495 size_t i;
496 0 ▶ for (i = 0; i < map->capacity; i++) {
Branch: 14 branches
BranchTrueFalseTotal
for (i = 0; i < map->capacity; i++) { 224 6 230
for (i = 0; i < map->capacity; i++) { 448 12 460
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 688 19 707
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 288 9 297
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
497 0 ▶ if (HM_SLOT_IS_LIVE(&map->nodes[i]) &&
Branch: 28 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 168 56 224
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 104 64 168
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 336 112 448
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 336 0 336
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 509 179 688
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 445 64 509
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 215 73 288
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 215 0 215
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
if (HM_SLOT_IS_LIVE(&map->nodes[i]) && 0 0 0
498 0 ▶ map->expires_at[i] && now > map->expires_at[i]) {
Branch: 28 branches
BranchTrueFalseTotal
map->expires_at[i] && now > map->expires_at[i]) { 104 0 104
map->expires_at[i] && now > map->expires_at[i]) { 0 104 104
map->expires_at[i] && now > map->expires_at[i]) { 336 0 336
map->expires_at[i] && now > map->expires_at[i]) { 0 336 336
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 445 0 445
map->expires_at[i] && now > map->expires_at[i]) { 5 440 445
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 215 0 215
map->expires_at[i] && now > map->expires_at[i]) { 30 185 215
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
map->expires_at[i] && now > map->expires_at[i]) { 0 0 0
499 0 ▶ if (HM_UNLIKELY(map->lru_prev))
Branch: 14 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 5 5
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 30 30
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
if (HM_UNLIKELY(map->lru_prev)) 0 0 0
500 0 HM_FN(lru_unlink)(map, (uint32_t)i);
501 0 HM_FN(tombstone_at)(map, i);
502 }
503 }
504 }
505  
506 0 static void HM_FN(purge)(HM_MAP_TYPE* map) {
507 0 ▶ if (!map || !map->expires_at) return;
Branch: 28 branches
BranchTrueFalseTotal
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 1 0 1
if (!map || !map->expires_at) return; 0 1 1
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 1 0 1
if (!map || !map->expires_at) return; 0 1 1
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
if (!map || !map->expires_at) return; 0 0 0
508 0 HM_FN(reap_expired)(map);
509 0 ▶ if (map->tombstones > 0) HM_FN(compact)(map);
Branch: 14 branches
BranchTrueFalseTotal
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 1 0 1
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 1 0 1
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
if (map->tombstones > 0) HM_FN(compact)(map); 0 0 0
510 }
511  
512 /* ---- clone: deep copy the entire map ---- */
513  
514 0 static HM_MAP_TYPE* HM_FN(clone)(const HM_MAP_TYPE* map) {
515 0 ▶ if (!map) return NULL;
Branch: 14 branches
BranchTrueFalseTotal
if (!map) return NULL; 0 4 4
if (!map) return NULL; 0 6 6
if (!map) return NULL; 0 4 4
if (!map) return NULL; 0 4 4
if (!map) return NULL; 0 0 0
if (!map) return NULL; 0 0 0
if (!map) return NULL; 0 2 2
if (!map) return NULL; 0 0 0
if (!map) return NULL; 0 0 0
if (!map) return NULL; 0 5 5
if (!map) return NULL; 0 1 1
if (!map) return NULL; 0 0 0
if (!map) return NULL; 0 0 0
if (!map) return NULL; 0 0 0
516  
517 0 HM_MAP_TYPE* c = (HM_MAP_TYPE*)malloc(sizeof(HM_MAP_TYPE));
518 0 ▶ if (!c) return NULL;
Branch: 14 branches
BranchTrueFalseTotal
if (!c) return NULL; 0 4 4
if (!c) return NULL; 0 6 6
if (!c) return NULL; 0 4 4
if (!c) return NULL; 0 4 4
if (!c) return NULL; 0 0 0
if (!c) return NULL; 0 0 0
if (!c) return NULL; 0 2 2
if (!c) return NULL; 0 0 0
if (!c) return NULL; 0 0 0
if (!c) return NULL; 0 5 5
if (!c) return NULL; 0 1 1
if (!c) return NULL; 0 0 0
if (!c) return NULL; 0 0 0
if (!c) return NULL; 0 0 0
519 0 *c = *map;
520 0 c->iter_pos = 0;
521 0 c->drain_pos = 0;
522 #ifdef HM_VALUE_IS_SV
523 18 c->free_value_fn = NULL; /* prevent double-dec on OOM cleanup */
524 18 c->free_value_now_fn = NULL;
525 #endif
526  
527 0 c->nodes = (HM_NODE_TYPE*)malloc(map->capacity * sizeof(HM_NODE_TYPE));
528 0 ▶ if (!c->nodes) { free(c); return NULL; }
Branch: 14 branches
BranchTrueFalseTotal
if (!c->nodes) { free(c); return NULL; } 0 4 4
if (!c->nodes) { free(c); return NULL; } 0 6 6
if (!c->nodes) { free(c); return NULL; } 0 4 4
if (!c->nodes) { free(c); return NULL; } 0 4 4
if (!c->nodes) { free(c); return NULL; } 0 0 0
if (!c->nodes) { free(c); return NULL; } 0 0 0
if (!c->nodes) { free(c); return NULL; } 0 2 2
if (!c->nodes) { free(c); return NULL; } 0 0 0
if (!c->nodes) { free(c); return NULL; } 0 0 0
if (!c->nodes) { free(c); return NULL; } 0 5 5
if (!c->nodes) { free(c); return NULL; } 0 1 1
if (!c->nodes) { free(c); return NULL; } 0 0 0
if (!c->nodes) { free(c); return NULL; } 0 0 0
if (!c->nodes) { free(c); return NULL; } 0 0 0
529 /* Null shared pointers so goto-fail destroy() won't free source arrays */
530 0 c->lru_prev = NULL;
531 0 c->lru_next = NULL;
532 0 c->expires_at = NULL;
533  
534 /* Start empty so that an OOM part-way leaves a valid map for destroy(). */
535 0 HM_FN(init_nodes)(c->nodes, map->capacity);
536 0 c->size = 0;
537 0 c->tombstones = 0;
538 {
539 size_t i;
540 0 ▶ for (i = 0; i < map->capacity; i++) {
Branch: 14 branches
BranchTrueFalseTotal
for (i = 0; i < map->capacity; i++) { 288 4 292
for (i = 0; i < map->capacity; i++) { 4400 6 4406
for (i = 0; i < map->capacity; i++) { 288 4 292
for (i = 0; i < map->capacity; i++) { 288 4 292
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 4112 2 4114
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 4512 5 4517
for (i = 0; i < map->capacity; i++) { 4096 1 4097
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
for (i = 0; i < map->capacity; i++) { 0 0 0
541 0 ▶ if (!HM_SLOT_IS_LIVE(&map->nodes[i])) {
Branch: 28 branches
BranchTrueFalseTotal
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 118 170 288
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 2 116 118
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 3119 1281 4400
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 202 2917 3119
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 118 170 288
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 2 116 118
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 118 170 288
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 2 116 118
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 3010 1102 4112
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 200 2810 3010
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 3156 1356 4512
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 200 2956 3156
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 3000 1096 4096
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 200 2800 3000
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
if (!HM_SLOT_IS_LIVE(&map->nodes[i])) { 0 0 0
542 /* Tombstones hold probe chains together, so they must survive the copy. */
543 0 ▶ if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) {
Branch: 14 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 2 170 172
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 202 1281 1483
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 2 170 172
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 2 170 172
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 0 0 0
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 0 0 0
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 200 1102 1302
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 0 0 0
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 0 0 0
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 200 1356 1556
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 200 1096 1296
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 0 0 0
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 0 0 0
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[i])) { 0 0 0
544 #ifdef HM_KEY_IS_INT
545 0 c->nodes[i].key = HM_TOMBSTONE_KEY;
546 #else
547 0 c->nodes[i].key = HM_STR_TOMBSTONE;
548 #endif
549 0 c->tombstones++;
550 }
551 0 continue;
552 }
553 #ifdef HM_KEY_IS_INT
554 0 c->nodes[i].key = map->nodes[i].key;
555 #else
556 {
557 0 uint32_t klen = HM_UNPACK_LEN(map->nodes[i].key_len);
558 0 c->nodes[i].key = (char*)malloc(klen + 1);
559 0 ▶ if (!c->nodes[i].key) goto fail;
Branch: 5 branches
BranchTrueFalseTotal
if (!c->nodes[i].key) goto fail; 0 116 116
if (!c->nodes[i].key) goto fail; 0 0 0
if (!c->nodes[i].key) goto fail; 0 2810 2810
if (!c->nodes[i].key) goto fail; 0 0 0
if (!c->nodes[i].key) goto fail; 0 0 0
560 0 memcpy(c->nodes[i].key, map->nodes[i].key, klen + 1);
561 0 c->nodes[i].key_len = map->nodes[i].key_len;
562 0 c->nodes[i].key_hash = map->nodes[i].key_hash;
563 }
564 #endif
565 #ifdef HM_VALUE_IS_STR
566 0 ▶ if (map->nodes[i].value) {
Branch: 4 branches
BranchTrueFalseTotal
if (map->nodes[i].value) { 0 0 0
if (map->nodes[i].value) { 2810 0 2810
if (map->nodes[i].value) { 0 0 0
if (map->nodes[i].value) { 0 0 0
567 0 uint32_t vlen = HM_UNPACK_LEN(map->nodes[i].val_len);
568 0 c->nodes[i].value = (char*)malloc(vlen + 1);
569 0 ▶ if (!c->nodes[i].value) goto fail;
Branch: 4 branches
BranchTrueFalseTotal
if (!c->nodes[i].value) goto fail; 0 0 0
if (!c->nodes[i].value) goto fail; 0 2810 2810
if (!c->nodes[i].value) goto fail; 0 0 0
if (!c->nodes[i].value) goto fail; 0 0 0
570 0 memcpy(c->nodes[i].value, map->nodes[i].value, vlen + 1);
571 }
572 0 c->nodes[i].val_len = map->nodes[i].val_len;
573 #elif defined(HM_VALUE_IS_SV)
574 3265 c->nodes[i].value = map->nodes[i].value;
575 /* the caller copies SV* values (needs pTHX) */
576 #else
577 0 c->nodes[i].value = map->nodes[i].value;
578 #endif
579 0 c->size++;
580 }
581 }
582  
583 0 ▶ if (map->lru_prev) {
Branch: 14 branches
BranchTrueFalseTotal
if (map->lru_prev) { 0 4 4
if (map->lru_prev) { 0 6 6
if (map->lru_prev) { 0 4 4
if (map->lru_prev) { 0 4 4
if (map->lru_prev) { 0 0 0
if (map->lru_prev) { 0 0 0
if (map->lru_prev) { 0 2 2
if (map->lru_prev) { 0 0 0
if (map->lru_prev) { 0 0 0
if (map->lru_prev) { 2 3 5
if (map->lru_prev) { 0 1 1
if (map->lru_prev) { 0 0 0
if (map->lru_prev) { 0 0 0
if (map->lru_prev) { 0 0 0
584 0 c->lru_prev = (uint32_t*)malloc(map->capacity * sizeof(uint32_t));
585 0 c->lru_next = (uint32_t*)malloc(map->capacity * sizeof(uint32_t));
586 0 ▶ if (!c->lru_prev || !c->lru_next) goto fail;
Branch: 28 branches
BranchTrueFalseTotal
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 2 0 2
if (!c->lru_prev || !c->lru_next) goto fail; 0 2 2
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
if (!c->lru_prev || !c->lru_next) goto fail; 0 0 0
587 0 memcpy(c->lru_prev, map->lru_prev, map->capacity * sizeof(uint32_t));
588 0 memcpy(c->lru_next, map->lru_next, map->capacity * sizeof(uint32_t));
589 }
590  
591 0 ▶ if (map->expires_at) {
Branch: 14 branches
BranchTrueFalseTotal
if (map->expires_at) { 4 0 4
if (map->expires_at) { 4 2 6
if (map->expires_at) { 4 0 4
if (map->expires_at) { 4 0 4
if (map->expires_at) { 0 0 0
if (map->expires_at) { 0 0 0
if (map->expires_at) { 0 2 2
if (map->expires_at) { 0 0 0
if (map->expires_at) { 0 0 0
if (map->expires_at) { 1 4 5
if (map->expires_at) { 0 1 1
if (map->expires_at) { 0 0 0
if (map->expires_at) { 0 0 0
if (map->expires_at) { 0 0 0
592 0 c->expires_at = (uint32_t*)malloc(map->capacity * sizeof(uint32_t));
593 0 ▶ if (!c->expires_at) goto fail;
Branch: 14 branches
BranchTrueFalseTotal
if (!c->expires_at) goto fail; 0 4 4
if (!c->expires_at) goto fail; 0 4 4
if (!c->expires_at) goto fail; 0 4 4
if (!c->expires_at) goto fail; 0 4 4
if (!c->expires_at) goto fail; 0 0 0
if (!c->expires_at) goto fail; 0 0 0
if (!c->expires_at) goto fail; 0 0 0
if (!c->expires_at) goto fail; 0 0 0
if (!c->expires_at) goto fail; 0 0 0
if (!c->expires_at) goto fail; 0 1 1
if (!c->expires_at) goto fail; 0 0 0
if (!c->expires_at) goto fail; 0 0 0
if (!c->expires_at) goto fail; 0 0 0
if (!c->expires_at) goto fail; 0 0 0
594 0 memcpy(c->expires_at, map->expires_at, map->capacity * sizeof(uint32_t));
595 }
596  
597 #ifdef HM_VALUE_IS_SV
598 18 c->free_value_fn = map->free_value_fn; /* restore after successful copy */
599 18 c->free_value_now_fn = map->free_value_now_fn;
600 #endif
601 0 return c;
602  
603 0 fail:
604 0 HM_FN(destroy)(c);
605 0 return NULL;
606 }
607  
608 /* ---- Rehash: resize to specific capacity ---- */
609  
610 1591 static bool HM_FN(rehash_to)(HM_MAP_TYPE* map, size_t new_capacity) {
611 1591 ▶ if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false;
Branch: 28 branches
BranchTrueFalseTotal
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 146 0 146
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 146 146
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 182 0 182
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 182 182
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 38 0 38
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 38 38
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 43 0 43
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 43 43
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 42 0 42
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 42 42
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 50 0 50
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 50 50
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 164 0 164
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 164 164
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 44 0 44
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 44 44
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 92 0 92
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 92 92
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 591 0 591
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 591 591
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 58 0 58
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 58 58
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 40 0 40
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 40 40
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 47 0 47
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 47 47
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 54 0 54
if (new_capacity == 0 || new_capacity > SIZE_MAX / sizeof(HM_NODE_TYPE)) return false; 0 54 54
612 1591 size_t old_capacity = map->capacity;
613 1591 HM_NODE_TYPE* old_nodes = map->nodes;
614 1591 size_t new_mask = new_capacity - 1;
615 1591 HM_NODE_TYPE* new_nodes = (HM_NODE_TYPE*)malloc(new_capacity * sizeof(HM_NODE_TYPE));
616 1591 ▶ if (!new_nodes) return false;
Branch: 14 branches
BranchTrueFalseTotal
if (!new_nodes) return false; 0 146 146
if (!new_nodes) return false; 0 182 182
if (!new_nodes) return false; 0 38 38
if (!new_nodes) return false; 0 43 43
if (!new_nodes) return false; 0 42 42
if (!new_nodes) return false; 0 50 50
if (!new_nodes) return false; 0 164 164
if (!new_nodes) return false; 0 44 44
if (!new_nodes) return false; 0 92 92
if (!new_nodes) return false; 0 591 591
if (!new_nodes) return false; 0 58 58
if (!new_nodes) return false; 0 40 40
if (!new_nodes) return false; 0 47 47
if (!new_nodes) return false; 0 54 54
617  
618 1591 uint32_t* new_lru_prev = NULL;
619 1591 uint32_t* new_lru_next = NULL;
620 1591 uint32_t* old_to_new = NULL;
621 1591 ▶ if (map->lru_prev) {
Branch: 14 branches
BranchTrueFalseTotal
if (map->lru_prev) { 29 117 146
if (map->lru_prev) { 39 143 182
if (map->lru_prev) { 11 27 38
if (map->lru_prev) { 11 32 43
if (map->lru_prev) { 0 42 42
if (map->lru_prev) { 8 42 50
if (map->lru_prev) { 17 147 164
if (map->lru_prev) { 0 44 44
if (map->lru_prev) { 8 84 92
if (map->lru_prev) { 455 136 591
if (map->lru_prev) { 0 58 58
if (map->lru_prev) { 0 40 40
if (map->lru_prev) { 8 39 47
if (map->lru_prev) { 0 54 54
622 0 ▶ if (new_capacity > (size_t)(uint32_t)-2) {
Branch: 14 branches
BranchTrueFalseTotal
if (new_capacity > (size_t)(uint32_t)-2) { 0 29 29
if (new_capacity > (size_t)(uint32_t)-2) { 0 39 39
if (new_capacity > (size_t)(uint32_t)-2) { 0 11 11
if (new_capacity > (size_t)(uint32_t)-2) { 0 11 11
if (new_capacity > (size_t)(uint32_t)-2) { 0 0 0
if (new_capacity > (size_t)(uint32_t)-2) { 0 8 8
if (new_capacity > (size_t)(uint32_t)-2) { 0 17 17
if (new_capacity > (size_t)(uint32_t)-2) { 0 0 0
if (new_capacity > (size_t)(uint32_t)-2) { 0 8 8
if (new_capacity > (size_t)(uint32_t)-2) { 0 455 455
if (new_capacity > (size_t)(uint32_t)-2) { 0 0 0
if (new_capacity > (size_t)(uint32_t)-2) { 0 0 0
if (new_capacity > (size_t)(uint32_t)-2) { 0 8 8
if (new_capacity > (size_t)(uint32_t)-2) { 0 0 0
623 0 free(new_nodes);
624 0 return false; /* capacity would overflow uint32_t LRU indices */
625 }
626 0 new_lru_prev = (uint32_t*)malloc(new_capacity * sizeof(uint32_t));
627 0 new_lru_next = (uint32_t*)malloc(new_capacity * sizeof(uint32_t));
628 0 old_to_new = (uint32_t*)malloc(old_capacity * sizeof(uint32_t));
629 0 ▶ if (!new_lru_prev || !new_lru_next || !old_to_new) {
Branch: 42 branches
BranchTrueFalseTotal
if (!new_lru_prev || !new_lru_next || !old_to_new) { 29 0 29
if (!new_lru_prev || !new_lru_next || !old_to_new) { 29 0 29
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 29 29
if (!new_lru_prev || !new_lru_next || !old_to_new) { 39 0 39
if (!new_lru_prev || !new_lru_next || !old_to_new) { 39 0 39
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 39 39
if (!new_lru_prev || !new_lru_next || !old_to_new) { 11 0 11
if (!new_lru_prev || !new_lru_next || !old_to_new) { 11 0 11
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 11 11
if (!new_lru_prev || !new_lru_next || !old_to_new) { 11 0 11
if (!new_lru_prev || !new_lru_next || !old_to_new) { 11 0 11
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 11 11
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 8 0 8
if (!new_lru_prev || !new_lru_next || !old_to_new) { 8 0 8
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 8 8
if (!new_lru_prev || !new_lru_next || !old_to_new) { 17 0 17
if (!new_lru_prev || !new_lru_next || !old_to_new) { 17 0 17
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 17 17
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 8 0 8
if (!new_lru_prev || !new_lru_next || !old_to_new) { 8 0 8
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 8 8
if (!new_lru_prev || !new_lru_next || !old_to_new) { 455 0 455
if (!new_lru_prev || !new_lru_next || !old_to_new) { 455 0 455
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 455 455
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 8 0 8
if (!new_lru_prev || !new_lru_next || !old_to_new) { 8 0 8
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 8 8
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
if (!new_lru_prev || !new_lru_next || !old_to_new) { 0 0 0
630 0 free(new_nodes); free(new_lru_prev); free(new_lru_next); free(old_to_new);
631 0 return false;
632 }
633 0 memset(new_lru_prev, 0xFF, new_capacity * sizeof(uint32_t));
634 0 memset(new_lru_next, 0xFF, new_capacity * sizeof(uint32_t));
635 0 memset(old_to_new, 0xFF, old_capacity * sizeof(uint32_t));
636 }
637  
638 1591 uint32_t* new_expires_at = NULL;
639 1591 ▶ if (map->expires_at) {
Branch: 14 branches
BranchTrueFalseTotal
if (map->expires_at) { 6 140 146
if (map->expires_at) { 12 170 182
if (map->expires_at) { 0 38 38
if (map->expires_at) { 0 43 43
if (map->expires_at) { 0 42 42
if (map->expires_at) { 0 50 50
if (map->expires_at) { 19 145 164
if (map->expires_at) { 0 44 44
if (map->expires_at) { 0 92 92
if (map->expires_at) { 9 582 591
if (map->expires_at) { 0 58 58
if (map->expires_at) { 0 40 40
if (map->expires_at) { 0 47 47
if (map->expires_at) { 0 54 54
640 0 new_expires_at = (uint32_t*)calloc(new_capacity, sizeof(uint32_t));
641 0 ▶ if (!new_expires_at) {
Branch: 14 branches
BranchTrueFalseTotal
if (!new_expires_at) { 0 6 6
if (!new_expires_at) { 0 12 12
if (!new_expires_at) { 0 0 0
if (!new_expires_at) { 0 0 0
if (!new_expires_at) { 0 0 0
if (!new_expires_at) { 0 0 0
if (!new_expires_at) { 0 19 19
if (!new_expires_at) { 0 0 0
if (!new_expires_at) { 0 0 0
if (!new_expires_at) { 0 9 9
if (!new_expires_at) { 0 0 0
if (!new_expires_at) { 0 0 0
if (!new_expires_at) { 0 0 0
if (!new_expires_at) { 0 0 0
642 0 free(new_nodes); free(new_lru_prev); free(new_lru_next); free(old_to_new);
643 0 return false;
644 }
645 }
646  
647 1591 HM_FN(init_nodes)(new_nodes, new_capacity);
648  
649 {
650 size_t i;
651 8812327 ▶ for (i = 0; i < old_capacity; i++) {
Branch: 14 branches
BranchTrueFalseTotal
for (i = 0; i < old_capacity; i++) { 562944 146 563090
for (i = 0; i < old_capacity; i++) { 568032 182 568214
for (i = 0; i < old_capacity; i++) { 197328 38 197366
for (i = 0; i < old_capacity; i++) { 394128 43 394171
for (i = 0; i < old_capacity; i++) { 557504 42 557546
for (i = 0; i < old_capacity; i++) { 557728 50 557778
for (i = 0; i < old_capacity; i++) { 568240 164 568404
for (i = 0; i < old_capacity; i++) { 557536 44 557580
for (i = 0; i < old_capacity; i++) { 559616 92 559708
for (i = 0; i < old_capacity; i++) { 1986288 591 1986879
for (i = 0; i < old_capacity; i++) { 922048 58 922106
for (i = 0; i < old_capacity; i++) { 557248 40 557288
for (i = 0; i < old_capacity; i++) { 360864 47 360911
for (i = 0; i < old_capacity; i++) { 461232 54 461286
652 8810736 ▶ if (HM_SLOT_IS_LIVE(&old_nodes[i])) {
Branch: 28 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 245365 317579 562944
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 175959 69406 245365
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 249176 318856 568032
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 179694 69482 249176
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 94667 102661 197328
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 71385 23282 94667
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 173963 220165 394128
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 132489 41474 173963
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 242489 315015 557504
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 173809 68680 242489
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 242657 315071 557728
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 173889 68768 242657
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 249354 318886 568240
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 180057 69297 249354
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 242501 315035 557536
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 173821 68680 242501
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 243828 315788 559616
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 174966 68862 243828
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 827507 1158781 1986288
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 565688 261819 827507
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 389830 532218 922048
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 257471 132359 389830
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 242297 314951 557248
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 173617 68680 242297
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 163313 197551 360864
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 112737 50576 163313
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 202569 258663 461232
if (HM_SLOT_IS_LIVE(&old_nodes[i])) { 133885 68684 202569
653 #ifdef HM_KEY_IS_INT
654 1802204 size_t index = hm_hash_int64((int64_t)old_nodes[i].key) & new_mask;
655 2244166 ▶ while (new_nodes[index].key != HM_EMPTY_KEY)
Branch: 9 branches
BranchTrueFalseTotal
while (new_nodes[index].key != HM_EMPTY_KEY) 44480 179694 224174
while (new_nodes[index].key != HM_EMPTY_KEY) 17559 71385 88944
while (new_nodes[index].key != HM_EMPTY_KEY) 32842 132489 165331
while (new_nodes[index].key != HM_EMPTY_KEY) 42556 173889 216445
while (new_nodes[index].key != HM_EMPTY_KEY) 43062 174966 218028
while (new_nodes[index].key != HM_EMPTY_KEY) 140547 565688 706235
while (new_nodes[index].key != HM_EMPTY_KEY) 61813 257471 319284
while (new_nodes[index].key != HM_EMPTY_KEY) 27279 112737 140016
while (new_nodes[index].key != HM_EMPTY_KEY) 31824 133885 165709
656 441962 index = (index + 1) & new_mask;
657 #else
658 877263 size_t index = (size_t)old_nodes[i].key_hash & new_mask;
659 1090309 ▶ while (new_nodes[index].key != NULL)
Branch: 5 branches
BranchTrueFalseTotal
while (new_nodes[index].key != NULL) 42644 175959 218603
while (new_nodes[index].key != NULL) 42244 173809 216053
while (new_nodes[index].key != NULL) 43732 180057 223789
while (new_nodes[index].key != NULL) 42244 173821 216065
while (new_nodes[index].key != NULL) 42182 173617 215799
660 213046 index = (index + 1) & new_mask;
661 #endif
662 2679467 new_nodes[index] = old_nodes[i];
663 2679467 ▶ if (old_to_new) old_to_new[i] = (uint32_t)index;
Branch: 14 branches
BranchTrueFalseTotal
if (old_to_new) old_to_new[i] = (uint32_t)index; 388 175571 175959
if (old_to_new) old_to_new[i] = (uint32_t)index; 283 179411 179694
if (old_to_new) old_to_new[i] = (uint32_t)index; 164 71221 71385
if (old_to_new) old_to_new[i] = (uint32_t)index; 164 132325 132489
if (old_to_new) old_to_new[i] = (uint32_t)index; 0 173809 173809
if (old_to_new) old_to_new[i] = (uint32_t)index; 80 173809 173889
if (old_to_new) old_to_new[i] = (uint32_t)index; 214 179843 180057
if (old_to_new) old_to_new[i] = (uint32_t)index; 0 173821 173821
if (old_to_new) old_to_new[i] = (uint32_t)index; 80 174886 174966
if (old_to_new) old_to_new[i] = (uint32_t)index; 31464 534224 565688
if (old_to_new) old_to_new[i] = (uint32_t)index; 0 257471 257471
if (old_to_new) old_to_new[i] = (uint32_t)index; 0 173617 173617
if (old_to_new) old_to_new[i] = (uint32_t)index; 80 112657 112737
if (old_to_new) old_to_new[i] = (uint32_t)index; 0 133885 133885
664 2679467 ▶ if (new_expires_at)
Branch: 14 branches
BranchTrueFalseTotal
if (new_expires_at) 104 175855 175959
if (new_expires_at) 336 179358 179694
if (new_expires_at) 0 71385 71385
if (new_expires_at) 0 132489 132489
if (new_expires_at) 0 173809 173809
if (new_expires_at) 0 173889 173889
if (new_expires_at) 440 179617 180057
if (new_expires_at) 0 173821 173821
if (new_expires_at) 0 174966 174966
if (new_expires_at) 185 565503 565688
if (new_expires_at) 0 257471 257471
if (new_expires_at) 0 173617 173617
if (new_expires_at) 0 112737 112737
if (new_expires_at) 0 133885 133885
665 0 new_expires_at[index] = map->expires_at[i];
666 }
667 }
668 }
669  
670 1591 ▶ if (map->lru_prev && map->lru_head != HM_LRU_NONE) {
Branch: 28 branches
BranchTrueFalseTotal
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 29 117 146
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 29 0 29
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 39 143 182
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 39 0 39
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 11 27 38
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 11 0 11
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 11 32 43
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 11 0 11
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 0 42 42
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 0 0 0
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 8 42 50
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 8 0 8
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 17 147 164
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 17 0 17
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 0 44 44
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 0 0 0
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 8 84 92
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 8 0 8
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 455 136 591
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 452 3 455
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 0 58 58
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 0 0 0
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 0 40 40
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 0 0 0
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 8 39 47
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 8 0 8
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 0 54 54
if (map->lru_prev && map->lru_head != HM_LRU_NONE) { 0 0 0
671 0 uint32_t old_idx = map->lru_head;
672 0 uint32_t prev_new = HM_LRU_NONE;
673 0 uint32_t new_head = HM_LRU_NONE;
674 0 uint32_t new_tail = HM_LRU_NONE;
675  
676 0 ▶ while (old_idx != HM_LRU_NONE) {
Branch: 14 branches
BranchTrueFalseTotal
while (old_idx != HM_LRU_NONE) { 388 29 417
while (old_idx != HM_LRU_NONE) { 283 39 322
while (old_idx != HM_LRU_NONE) { 164 11 175
while (old_idx != HM_LRU_NONE) { 164 11 175
while (old_idx != HM_LRU_NONE) { 0 0 0
while (old_idx != HM_LRU_NONE) { 80 8 88
while (old_idx != HM_LRU_NONE) { 214 17 231
while (old_idx != HM_LRU_NONE) { 0 0 0
while (old_idx != HM_LRU_NONE) { 80 8 88
while (old_idx != HM_LRU_NONE) { 31464 452 31916
while (old_idx != HM_LRU_NONE) { 0 0 0
while (old_idx != HM_LRU_NONE) { 0 0 0
while (old_idx != HM_LRU_NONE) { 80 8 88
while (old_idx != HM_LRU_NONE) { 0 0 0
677 0 uint32_t next_old = map->lru_next[old_idx];
678 0 uint32_t ni = old_to_new[old_idx];
679 0 ▶ if (ni != HM_LRU_NONE) {
Branch: 14 branches
BranchTrueFalseTotal
if (ni != HM_LRU_NONE) { 388 0 388
if (ni != HM_LRU_NONE) { 283 0 283
if (ni != HM_LRU_NONE) { 164 0 164
if (ni != HM_LRU_NONE) { 164 0 164
if (ni != HM_LRU_NONE) { 0 0 0
if (ni != HM_LRU_NONE) { 80 0 80
if (ni != HM_LRU_NONE) { 214 0 214
if (ni != HM_LRU_NONE) { 0 0 0
if (ni != HM_LRU_NONE) { 80 0 80
if (ni != HM_LRU_NONE) { 31464 0 31464
if (ni != HM_LRU_NONE) { 0 0 0
if (ni != HM_LRU_NONE) { 0 0 0
if (ni != HM_LRU_NONE) { 80 0 80
if (ni != HM_LRU_NONE) { 0 0 0
680 0 new_lru_prev[ni] = prev_new;
681 0 new_lru_next[ni] = HM_LRU_NONE;
682 0 ▶ if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni;
Branch: 14 branches
BranchTrueFalseTotal
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 359 29 388
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 244 39 283
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 153 11 164
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 153 11 164
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 0 0 0
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 72 8 80
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 197 17 214
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 0 0 0
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 72 8 80
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 31012 452 31464
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 0 0 0
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 0 0 0
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 72 8 80
if (prev_new != HM_LRU_NONE) new_lru_next[prev_new] = ni; 0 0 0
683 0 else new_head = ni;
684 0 new_tail = ni;
685 0 prev_new = ni;
686 }
687 0 old_idx = next_old;
688 }
689  
690 0 free(map->lru_prev); free(map->lru_next);
691 0 map->lru_prev = new_lru_prev;
692 0 map->lru_next = new_lru_next;
693 0 map->lru_head = new_head;
694 0 map->lru_tail = new_tail;
695 1008 ▶ } else if (map->lru_prev) {
Branch: 14 branches
BranchTrueFalseTotal
} else if (map->lru_prev) { 0 117 117
} else if (map->lru_prev) { 0 143 143
} else if (map->lru_prev) { 0 27 27
} else if (map->lru_prev) { 0 32 32
} else if (map->lru_prev) { 0 42 42
} else if (map->lru_prev) { 0 42 42
} else if (map->lru_prev) { 0 147 147
} else if (map->lru_prev) { 0 44 44
} else if (map->lru_prev) { 0 84 84
} else if (map->lru_prev) { 3 136 139
} else if (map->lru_prev) { 0 58 58
} else if (map->lru_prev) { 0 40 40
} else if (map->lru_prev) { 0 39 39
} else if (map->lru_prev) { 0 54 54
696 0 free(map->lru_prev); free(map->lru_next);
697 0 map->lru_prev = new_lru_prev;
698 0 map->lru_next = new_lru_next;
699 }
700 1591 free(old_to_new);
701  
702 1591 ▶ if (map->expires_at) {
Branch: 14 branches
BranchTrueFalseTotal
if (map->expires_at) { 6 140 146
if (map->expires_at) { 12 170 182
if (map->expires_at) { 0 38 38
if (map->expires_at) { 0 43 43
if (map->expires_at) { 0 42 42
if (map->expires_at) { 0 50 50
if (map->expires_at) { 19 145 164
if (map->expires_at) { 0 44 44
if (map->expires_at) { 0 92 92
if (map->expires_at) { 9 582 591
if (map->expires_at) { 0 58 58
if (map->expires_at) { 0 40 40
if (map->expires_at) { 0 47 47
if (map->expires_at) { 0 54 54
703 0 free(map->expires_at);
704 0 map->expires_at = new_expires_at;
705 }
706  
707 1591 free(old_nodes);
708 1591 map->nodes = new_nodes;
709 1591 map->capacity = new_capacity;
710 1591 map->mask = new_mask;
711 1591 map->tombstones = 0;
712 1591 map->iter_pos = 0;
713 1591 map->drain_pos = 0;
714 1591 return true;
715 }
716  
717 817 static bool HM_FN(resize)(HM_MAP_TYPE* map) {
718 817 ▶ if (map->capacity > SIZE_MAX / 2) return false;
Branch: 14 branches
BranchTrueFalseTotal
if (map->capacity > SIZE_MAX / 2) return false; 0 95 95
if (map->capacity > SIZE_MAX / 2) return false; 0 117 117
if (map->capacity > SIZE_MAX / 2) return false; 0 28 28
if (map->capacity > SIZE_MAX / 2) return false; 0 33 33
if (map->capacity > SIZE_MAX / 2) return false; 0 31 31
if (map->capacity > SIZE_MAX / 2) return false; 0 33 33
if (map->capacity > SIZE_MAX / 2) return false; 0 122 122
if (map->capacity > SIZE_MAX / 2) return false; 0 32 32
if (map->capacity > SIZE_MAX / 2) return false; 0 69 69
if (map->capacity > SIZE_MAX / 2) return false; 0 121 121
if (map->capacity > SIZE_MAX / 2) return false; 0 40 40
if (map->capacity > SIZE_MAX / 2) return false; 0 29 29
if (map->capacity > SIZE_MAX / 2) return false; 0 30 30
if (map->capacity > SIZE_MAX / 2) return false; 0 37 37
719 817 return HM_FN(rehash_to)(map, map->capacity * 2);
720 }
721  
722 756 static bool HM_FN(compact)(HM_MAP_TYPE* map) {
723 756 return HM_FN(rehash_to)(map, map->capacity);
724 }
725  
726 127 static bool HM_FN(reserve)(HM_MAP_TYPE* map, size_t count) {
727 127 ▶ if (count > SIZE_MAX / 4) return false;
Branch: 14 branches
BranchTrueFalseTotal
if (count > SIZE_MAX / 4) return false; 0 14 14
if (count > SIZE_MAX / 4) return false; 0 12 12
if (count > SIZE_MAX / 4) return false; 0 9 9
if (count > SIZE_MAX / 4) return false; 0 9 9
if (count > SIZE_MAX / 4) return false; 0 7 7
if (count > SIZE_MAX / 4) return false; 0 1 1
if (count > SIZE_MAX / 4) return false; 0 11 11
if (count > SIZE_MAX / 4) return false; 0 8 8
if (count > SIZE_MAX / 4) return false; 0 2 2
if (count > SIZE_MAX / 4) return false; 0 34 34
if (count > SIZE_MAX / 4) return false; 0 5 5
if (count > SIZE_MAX / 4) return false; 0 8 8
if (count > SIZE_MAX / 4) return false; 0 1 1
if (count > SIZE_MAX / 4) return false; 0 6 6
728 /* Compute capacity for count entries at 75% load factor */
729 127 size_t needed = (count * 4 + 2) / 3;
730 127 ▶ if (needed <= map->capacity) return true;
Branch: 14 branches
BranchTrueFalseTotal
if (needed <= map->capacity) return true; 12 2 14
if (needed <= map->capacity) return true; 10 2 12
if (needed <= map->capacity) return true; 7 2 9
if (needed <= map->capacity) return true; 7 2 9
if (needed <= map->capacity) return true; 7 0 7
if (needed <= map->capacity) return true; 1 0 1
if (needed <= map->capacity) return true; 11 0 11
if (needed <= map->capacity) return true; 7 1 8
if (needed <= map->capacity) return true; 2 0 2
if (needed <= map->capacity) return true; 25 9 34
if (needed <= map->capacity) return true; 5 0 5
if (needed <= map->capacity) return true; 8 0 8
if (needed <= map->capacity) return true; 1 0 1
if (needed <= map->capacity) return true; 6 0 6
731 0 size_t cap = map->capacity;
732 0 ▶ while (cap < needed) {
Branch: 14 branches
BranchTrueFalseTotal
while (cap < needed) { 6 2 8
while (cap < needed) { 6 2 8
while (cap < needed) { 6 2 8
while (cap < needed) { 6 2 8
while (cap < needed) { 0 0 0
while (cap < needed) { 0 0 0
while (cap < needed) { 0 0 0
while (cap < needed) { 1 1 2
while (cap < needed) { 0 0 0
while (cap < needed) { 47 9 56
while (cap < needed) { 0 0 0
while (cap < needed) { 0 0 0
while (cap < needed) { 0 0 0
while (cap < needed) { 0 0 0
733 0 ▶ if (cap > SIZE_MAX / 2) return false;
Branch: 14 branches
BranchTrueFalseTotal
if (cap > SIZE_MAX / 2) return false; 0 6 6
if (cap > SIZE_MAX / 2) return false; 0 6 6
if (cap > SIZE_MAX / 2) return false; 0 6 6
if (cap > SIZE_MAX / 2) return false; 0 6 6
if (cap > SIZE_MAX / 2) return false; 0 0 0
if (cap > SIZE_MAX / 2) return false; 0 0 0
if (cap > SIZE_MAX / 2) return false; 0 0 0
if (cap > SIZE_MAX / 2) return false; 0 1 1
if (cap > SIZE_MAX / 2) return false; 0 0 0
if (cap > SIZE_MAX / 2) return false; 0 47 47
if (cap > SIZE_MAX / 2) return false; 0 0 0
if (cap > SIZE_MAX / 2) return false; 0 0 0
if (cap > SIZE_MAX / 2) return false; 0 0 0
if (cap > SIZE_MAX / 2) return false; 0 0 0
734 0 cap <<= 1;
735 }
736 0 return HM_FN(rehash_to)(map, cap);
737 }
738  
739 /* ---- find_node: find existing key or return empty/capacity (not found) ---- */
740  
741 #ifdef HM_KEY_IS_INT
742  
743 1374813 static inline size_t HM_FN(find_node)(const HM_MAP_TYPE* map, HM_INT_TYPE key) {
744 1374813 size_t index = hm_hash_int64((int64_t)key) & map->mask;
745 1374813 const size_t original_index = index;
746 1374813 const HM_NODE_TYPE* nodes = map->nodes;
747  
748 do {
749 1629515 HM_INT_TYPE k = nodes[index].key;
750 1629515 ▶ if (k == key) return index;
Branch: 9 branches
BranchTrueFalseTotal
if (k == key) return index; 138396 29615 168011
if (k == key) return index; 64881 17464 82345
if (k == key) return index; 104881 21344 126225
if (k == key) return index; 130014 23344 153358
if (k == key) return index; 130119 23368 153487
if (k == key) return index; 403340 61753 465093
if (k == key) return index; 203033 36631 239664
if (k == key) return index; 90014 19457 109471
if (k == key) return index; 110038 21823 131861
751 254799 ▶ if (k == HM_EMPTY_KEY) return index;
Branch: 9 branches
BranchTrueFalseTotal
if (k == HM_EMPTY_KEY) return index; 11 29604 29615
if (k == HM_EMPTY_KEY) return index; 5 17459 17464
if (k == HM_EMPTY_KEY) return index; 5 21339 21344
if (k == HM_EMPTY_KEY) return index; 4 23340 23344
if (k == HM_EMPTY_KEY) return index; 5 23363 23368
if (k == HM_EMPTY_KEY) return index; 40 61713 61753
if (k == HM_EMPTY_KEY) return index; 10 36621 36631
if (k == HM_EMPTY_KEY) return index; 5 19452 19457
if (k == HM_EMPTY_KEY) return index; 12 21811 21823
752 254702 index = (index + 1) & map->mask;
753 254702 ▶ } while (HM_LIKELY(index != original_index));
Branch: 9 branches
BranchTrueFalseTotal
} while (HM_LIKELY(index != original_index)); 29604 0 29604
} while (HM_LIKELY(index != original_index)); 17459 0 17459
} while (HM_LIKELY(index != original_index)); 21339 0 21339
} while (HM_LIKELY(index != original_index)); 23340 0 23340
} while (HM_LIKELY(index != original_index)); 23363 0 23363
} while (HM_LIKELY(index != original_index)); 61713 0 61713
} while (HM_LIKELY(index != original_index)); 36621 0 36621
} while (HM_LIKELY(index != original_index)); 19452 0 19452
} while (HM_LIKELY(index != original_index)); 21811 0 21811
754  
755 0 return map->capacity;
756 }
757  
758 #else /* string keys */
759  
760 679210 static inline size_t HM_FN(find_node)(const HM_MAP_TYPE* map,
761 const char* key, uint32_t key_len, uint32_t key_hash) {
762 679210 size_t index = (size_t)key_hash & map->mask;
763 679210 const size_t original_index = index;
764 679210 const HM_NODE_TYPE* nodes = map->nodes;
765  
766 do {
767 801338 ▶ if (nodes[index].key == NULL) return index;
Branch: 5 branches
BranchTrueFalseTotal
if (nodes[index].key == NULL) return index; 5 162150 162155
if (nodes[index].key == NULL) return index; 9 152873 152882
if (nodes[index].key == NULL) return index; 8 160502 160510
if (nodes[index].key == NULL) return index; 15 172891 172906
if (nodes[index].key == NULL) return index; 10 152875 152885
768 801291 ▶ if (nodes[index].key != HM_STR_TOMBSTONE &&
Branch: 5 branches
BranchTrueFalseTotal
if (nodes[index].key != HM_STR_TOMBSTONE && 154402 7748 162150
if (nodes[index].key != HM_STR_TOMBSTONE && 145185 7688 152873
if (nodes[index].key != HM_STR_TOMBSTONE && 152477 8025 160502
if (nodes[index].key != HM_STR_TOMBSTONE && 165202 7689 172891
if (nodes[index].key != HM_STR_TOMBSTONE && 145186 7689 152875
769 762452 ▶ nodes[index].key_hash == key_hash &&
Branch: 5 branches
BranchTrueFalseTotal
nodes[index].key_hash == key_hash && 135416 18986 154402
nodes[index].key_hash == key_hash && 130048 15137 145185
nodes[index].key_hash == key_hash && 133587 18890 152477
nodes[index].key_hash == key_hash && 150062 15140 165202
nodes[index].key_hash == key_hash && 130050 15136 145186
770 679163 ▶ HM_UNPACK_LEN(nodes[index].key_len) == key_len &&
Branch: 5 branches
BranchTrueFalseTotal
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 135416 0 135416
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 130048 0 130048
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 133587 0 133587
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 150062 0 150062
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 130050 0 130050
771 679163 ▶ memcmp(nodes[index].key, key, key_len) == 0) {
Branch: 5 branches
BranchTrueFalseTotal
memcmp(nodes[index].key, key, key_len) == 0) { 135416 0 135416
memcmp(nodes[index].key, key, key_len) == 0) { 130048 0 130048
memcmp(nodes[index].key, key, key_len) == 0) { 133587 0 133587
memcmp(nodes[index].key, key, key_len) == 0) { 150062 0 150062
memcmp(nodes[index].key, key, key_len) == 0) { 130050 0 130050
772 679163 return index;
773 }
774 122128 index = (index + 1) & map->mask;
775 122128 ▶ } while (HM_LIKELY(index != original_index));
Branch: 5 branches
BranchTrueFalseTotal
} while (HM_LIKELY(index != original_index)); 26734 0 26734
} while (HM_LIKELY(index != original_index)); 22825 0 22825
} while (HM_LIKELY(index != original_index)); 26915 0 26915
} while (HM_LIKELY(index != original_index)); 22829 0 22829
} while (HM_LIKELY(index != original_index)); 22825 0 22825
776  
777 0 return map->capacity;
778 }
779  
780 #endif
781  
782 /* ---- find_slot_for_insert ---- */
783  
784 #ifdef HM_KEY_IS_INT
785  
786 1117837 static inline size_t HM_FN(find_slot_for_insert)(HM_MAP_TYPE* map, HM_INT_TYPE key, bool* found) {
787 1117837 size_t index = hm_hash_int64((int64_t)key) & map->mask;
788 1117837 const size_t original_index = index;
789 1117837 HM_NODE_TYPE* nodes = map->nodes;
790 1117837 size_t first_tombstone = map->capacity;
791  
792 do {
793 3139953 HM_INT_TYPE k = nodes[index].key;
794 3139953 ▶ if (k == key) {
Branch: 9 branches
BranchTrueFalseTotal
if (k == key) { 15 267632 267647
if (k == key) { 7 99552 99559
if (k == key) { 7 179411 179418
if (k == key) { 1 248726 248727
if (k == key) { 8 250699 250707
if (k == key) { 17 1308159 1308176
if (k == key) { 3 406663 406666
if (k == key) { 1 168766 168767
if (k == key) { 2 210284 210286
795 61 *found = true;
796 61 return index;
797 }
798 3139892 ▶ if (k == HM_EMPTY_KEY) {
Branch: 9 branches
BranchTrueFalseTotal
if (k == HM_EMPTY_KEY) { 86704 180928 267632
if (k == HM_EMPTY_KEY) { 30813 68739 99552
if (k == HM_EMPTY_KEY) { 50873 128538 179411
if (k == HM_EMPTY_KEY) { 80599 168127 248726
if (k == HM_EMPTY_KEY) { 81216 169483 250699
if (k == HM_EMPTY_KEY) { 492585 815574 1308159
if (k == HM_EMPTY_KEY) { 153256 253407 406663
if (k == HM_EMPTY_KEY) { 60496 108270 168766
if (k == HM_EMPTY_KEY) { 81234 129050 210284
799 1117776 *found = false;
800 1117776 ▶ return (first_tombstone < map->capacity) ? first_tombstone : index;
Branch: 9 branches
BranchTrueFalseTotal
return (first_tombstone < map->capacity) ? first_tombstone : index; 2444 84260 86704
return (first_tombstone < map->capacity) ? first_tombstone : index; 156 30657 30813
return (first_tombstone < map->capacity) ? first_tombstone : index; 156 50717 50873
return (first_tombstone < map->capacity) ? first_tombstone : index; 1959 78640 80599
return (first_tombstone < map->capacity) ? first_tombstone : index; 1958 79258 81216
return (first_tombstone < map->capacity) ? first_tombstone : index; 65725 426860 492585
return (first_tombstone < map->capacity) ? first_tombstone : index; 7226 146030 153256
return (first_tombstone < map->capacity) ? first_tombstone : index; 1958 58538 60496
return (first_tombstone < map->capacity) ? first_tombstone : index; 3609 77625 81234
801 }
802 2022116 ▶ if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) {
Branch: 18 branches
BranchTrueFalseTotal
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 2999 177929 180928
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 2445 554 2999
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 256 68483 68739
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 156 100 256
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 256 128282 128538
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 156 100 256
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 2181 165946 168127
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 1959 222 2181
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 2180 167303 169483
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 1958 222 2180
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 131590 683984 815574
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 65726 65864 131590
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 7623 245784 253407
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 7227 396 7623
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 2180 106090 108270
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 1958 222 2180
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 3853 125197 129050
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 3609 244 3853
803 85194 first_tombstone = index;
804 }
805 2022116 index = (index + 1) & map->mask;
806 2022116 ▶ } while (index != original_index);
Branch: 9 branches
BranchTrueFalseTotal
} while (index != original_index); 180928 0 180928
} while (index != original_index); 68739 0 68739
} while (index != original_index); 128538 0 128538
} while (index != original_index); 168127 0 168127
} while (index != original_index); 169483 0 169483
} while (index != original_index); 815574 0 815574
} while (index != original_index); 253407 0 253407
} while (index != original_index); 108270 0 108270
} while (index != original_index); 129050 0 129050
807  
808 0 *found = false;
809 0 return first_tombstone;
810 }
811  
812 #else /* string keys */
813  
814 409660 static inline size_t HM_FN(find_slot_for_insert)(HM_MAP_TYPE* map,
815 const char* key, uint32_t key_len,
816 uint32_t key_hash, bool* found) {
817 409660 size_t index = (size_t)key_hash & map->mask;
818 409660 const size_t original_index = index;
819 409660 HM_NODE_TYPE* nodes = map->nodes;
820 409660 size_t first_tombstone = map->capacity;
821  
822 do {
823 1278895 ▶ if (nodes[index].key == NULL) {
Branch: 5 branches
BranchTrueFalseTotal
if (nodes[index].key == NULL) { 82887 173862 256749
if (nodes[index].key == NULL) { 80232 171256 251488
if (nodes[index].key == NULL) { 86067 181811 267878
if (nodes[index].key == NULL) { 80282 171279 251561
if (nodes[index].key == NULL) { 80131 171088 251219
824 409599 *found = false;
825 409599 ▶ return (first_tombstone < map->capacity) ? first_tombstone : index;
Branch: 5 branches
BranchTrueFalseTotal
return (first_tombstone < map->capacity) ? first_tombstone : index; 2164 80723 82887
return (first_tombstone < map->capacity) ? first_tombstone : index; 1804 78428 80232
return (first_tombstone < map->capacity) ? first_tombstone : index; 2071 83996 86067
return (first_tombstone < map->capacity) ? first_tombstone : index; 1804 78478 80282
return (first_tombstone < map->capacity) ? first_tombstone : index; 1804 78327 80131
826 }
827 869296 ▶ if (nodes[index].key == HM_STR_TOMBSTONE) {
Branch: 5 branches
BranchTrueFalseTotal
if (nodes[index].key == HM_STR_TOMBSTONE) { 2512 171350 173862
if (nodes[index].key == HM_STR_TOMBSTONE) { 1932 169324 171256
if (nodes[index].key == HM_STR_TOMBSTONE) { 2409 179402 181811
if (nodes[index].key == HM_STR_TOMBSTONE) { 1932 169347 171279
if (nodes[index].key == HM_STR_TOMBSTONE) { 1932 169156 171088
828 10717 ▶ if (first_tombstone >= map->capacity) first_tombstone = index;
Branch: 5 branches
BranchTrueFalseTotal
if (first_tombstone >= map->capacity) first_tombstone = index; 2164 348 2512
if (first_tombstone >= map->capacity) first_tombstone = index; 1804 128 1932
if (first_tombstone >= map->capacity) first_tombstone = index; 2071 338 2409
if (first_tombstone >= map->capacity) first_tombstone = index; 1804 128 1932
if (first_tombstone >= map->capacity) first_tombstone = index; 1804 128 1932
829 858579 ▶ } else if (nodes[index].key_hash == key_hash &&
Branch: 5 branches
BranchTrueFalseTotal
} else if (nodes[index].key_hash == key_hash && 18 171332 171350
} else if (nodes[index].key_hash == key_hash && 6 169318 169324
} else if (nodes[index].key_hash == key_hash && 20 179382 179402
} else if (nodes[index].key_hash == key_hash && 11 169336 169347
} else if (nodes[index].key_hash == key_hash && 6 169150 169156
830 61 ▶ HM_UNPACK_LEN(nodes[index].key_len) == key_len &&
Branch: 5 branches
BranchTrueFalseTotal
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 18 0 18
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 6 0 6
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 20 0 20
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 11 0 11
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 6 0 6
831 61 ▶ memcmp(nodes[index].key, key, key_len) == 0) {
Branch: 5 branches
BranchTrueFalseTotal
memcmp(nodes[index].key, key, key_len) == 0) { 18 0 18
memcmp(nodes[index].key, key, key_len) == 0) { 6 0 6
memcmp(nodes[index].key, key, key_len) == 0) { 20 0 20
memcmp(nodes[index].key, key, key_len) == 0) { 11 0 11
memcmp(nodes[index].key, key, key_len) == 0) { 6 0 6
832 61 *found = true;
833 61 return index;
834 }
835 869235 index = (index + 1) & map->mask;
836 869235 ▶ } while (index != original_index);
Branch: 5 branches
BranchTrueFalseTotal
} while (index != original_index); 173844 0 173844
} while (index != original_index); 171250 0 171250
} while (index != original_index); 181791 0 181791
} while (index != original_index); 171268 0 171268
} while (index != original_index); 171082 0 171082
837  
838 0 *found = false;
839 0 return first_tombstone;
840 }
841  
842 #endif
843  
844 /* ---- put ---- */
845  
846 #ifdef HM_KEY_IS_INT
847  
848 21096 static inline bool HM_FN(key_is_reserved)(HM_INT_TYPE key) {
849 21096 ▶ return HM_IS_RESERVED_KEY(key);
Branch: 18 branches
BranchTrueFalseTotal
return HM_IS_RESERVED_KEY(key); 8 1 9
return HM_IS_RESERVED_KEY(key); 0 8 8
return HM_IS_RESERVED_KEY(key); 5 0 5
return HM_IS_RESERVED_KEY(key); 0 5 5
return HM_IS_RESERVED_KEY(key); 5 0 5
return HM_IS_RESERVED_KEY(key); 0 5 5
return HM_IS_RESERVED_KEY(key); 1 0 1
return HM_IS_RESERVED_KEY(key); 0 1 1
return HM_IS_RESERVED_KEY(key); 1 0 1
return HM_IS_RESERVED_KEY(key); 0 1 1
return HM_IS_RESERVED_KEY(key); 21062 1 21063
return HM_IS_RESERVED_KEY(key); 1 21061 21062
return HM_IS_RESERVED_KEY(key); 3 1 4
return HM_IS_RESERVED_KEY(key); 1 2 3
return HM_IS_RESERVED_KEY(key); 1 0 1
return HM_IS_RESERVED_KEY(key); 0 1 1
return HM_IS_RESERVED_KEY(key); 6 1 7
return HM_IS_RESERVED_KEY(key); 1 5 6
850 }
851  
852 1073645 static bool HM_FN(put)(HM_MAP_TYPE* map, HM_INT_TYPE key,
853 #ifdef HM_VALUE_IS_STR
854 const char* value, uint32_t val_len, bool val_utf8,
855 #elif defined(HM_VALUE_IS_SV)
856 void* value,
857 #else
858 HM_INT_TYPE value,
859 #endif
860 uint32_t entry_ttl) {
861 1073645 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return false;
Branch: 27 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return false; 86002 0 86002
if (!map || HM_IS_RESERVED_KEY(key)) return false; 86001 1 86002
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 86000 86001
if (!map || HM_IS_RESERVED_KEY(key)) return false; 30631 0 30631
if (!map || HM_IS_RESERVED_KEY(key)) return false; 30630 1 30631
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 30629 30630
if (!map || HM_IS_RESERVED_KEY(key)) return false; 50691 0 50691
if (!map || HM_IS_RESERVED_KEY(key)) return false; 50690 1 50691
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 50689 50690
if (!map || HM_IS_RESERVED_KEY(key)) return false; 80421 0 80421
if (!map || HM_IS_RESERVED_KEY(key)) return false; 80420 1 80421
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 80419 80420
if (!map || HM_IS_RESERVED_KEY(key)) return false; 81036 0 81036
if (!map || HM_IS_RESERVED_KEY(key)) return false; 81035 1 81036
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 81034 81035
if (!map || HM_IS_RESERVED_KEY(key)) return false; 450054 0 450054
if (!map || HM_IS_RESERVED_KEY(key)) return false; 450053 1 450054
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 450052 450053
if (!map || HM_IS_RESERVED_KEY(key)) return false; 153258 0 153258
if (!map || HM_IS_RESERVED_KEY(key)) return false; 153257 1 153258
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 153256 153257
if (!map || HM_IS_RESERVED_KEY(key)) return false; 60317 0 60317
if (!map || HM_IS_RESERVED_KEY(key)) return false; 60316 1 60317
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 60315 60316
if (!map || HM_IS_RESERVED_KEY(key)) return false; 81235 0 81235
if (!map || HM_IS_RESERVED_KEY(key)) return false; 81234 1 81235
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 81233 81234
862  
863 1073627 ▶ HM_ENSURE_CAPACITY(map, false);
Branch: 54 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, false); 148 85852 86000
HM_ENSURE_CAPACITY(map, false); 12 136 148
HM_ENSURE_CAPACITY(map, false); 148 0 148
HM_ENSURE_CAPACITY(map, false); 31 117 148
HM_ENSURE_CAPACITY(map, false); 0 31 31
HM_ENSURE_CAPACITY(map, false); 0 117 117
HM_ENSURE_CAPACITY(map, false); 34 30595 30629
HM_ENSURE_CAPACITY(map, false); 0 34 34
HM_ENSURE_CAPACITY(map, false); 34 0 34
HM_ENSURE_CAPACITY(map, false); 6 28 34
HM_ENSURE_CAPACITY(map, false); 0 6 6
HM_ENSURE_CAPACITY(map, false); 0 28 28
HM_ENSURE_CAPACITY(map, false); 39 50650 50689
HM_ENSURE_CAPACITY(map, false); 0 39 39
HM_ENSURE_CAPACITY(map, false); 39 0 39
HM_ENSURE_CAPACITY(map, false); 6 33 39
HM_ENSURE_CAPACITY(map, false); 0 6 6
HM_ENSURE_CAPACITY(map, false); 0 33 33
HM_ENSURE_CAPACITY(map, false); 39 80380 80419
HM_ENSURE_CAPACITY(map, false); 0 39 39
HM_ENSURE_CAPACITY(map, false); 39 0 39
HM_ENSURE_CAPACITY(map, false); 6 33 39
HM_ENSURE_CAPACITY(map, false); 0 6 6
HM_ENSURE_CAPACITY(map, false); 0 33 33
HM_ENSURE_CAPACITY(map, false); 75 80959 81034
HM_ENSURE_CAPACITY(map, false); 0 75 75
HM_ENSURE_CAPACITY(map, false); 75 0 75
HM_ENSURE_CAPACITY(map, false); 6 69 75
HM_ENSURE_CAPACITY(map, false); 0 6 6
HM_ENSURE_CAPACITY(map, false); 0 69 69
HM_ENSURE_CAPACITY(map, false); 557 449495 450052
HM_ENSURE_CAPACITY(map, false); 8 549 557
HM_ENSURE_CAPACITY(map, false); 557 0 557
HM_ENSURE_CAPACITY(map, false); 436 121 557
HM_ENSURE_CAPACITY(map, false); 0 436 436
HM_ENSURE_CAPACITY(map, false); 0 121 121
HM_ENSURE_CAPACITY(map, false); 40 153216 153256
HM_ENSURE_CAPACITY(map, false); 0 40 40
HM_ENSURE_CAPACITY(map, false); 40 0 40
HM_ENSURE_CAPACITY(map, false); 0 40 40
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 40 40
HM_ENSURE_CAPACITY(map, false); 36 60279 60315
HM_ENSURE_CAPACITY(map, false); 0 36 36
HM_ENSURE_CAPACITY(map, false); 36 0 36
HM_ENSURE_CAPACITY(map, false); 6 30 36
HM_ENSURE_CAPACITY(map, false); 0 6 6
HM_ENSURE_CAPACITY(map, false); 0 30 30
HM_ENSURE_CAPACITY(map, false); 37 81196 81233
HM_ENSURE_CAPACITY(map, false); 0 37 37
HM_ENSURE_CAPACITY(map, false); 37 0 37
HM_ENSURE_CAPACITY(map, false); 0 37 37
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 37 37
864  
865 bool found;
866 1073627 size_t index = HM_FN(find_slot_for_insert)(map, key, &found);
867 1073627 ▶ if (index >= map->capacity) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (index >= map->capacity) return false; 0 86000 86000
if (index >= map->capacity) return false; 0 30629 30629
if (index >= map->capacity) return false; 0 50689 50689
if (index >= map->capacity) return false; 0 80419 80419
if (index >= map->capacity) return false; 0 81034 81034
if (index >= map->capacity) return false; 0 450052 450052
if (index >= map->capacity) return false; 0 153256 153256
if (index >= map->capacity) return false; 0 60315 60315
if (index >= map->capacity) return false; 0 81233 81233
868  
869 1073627 ▶ if (!found && map->max_size > 0 && map->size >= map->max_size) {
Branch: 27 branches
BranchTrueFalseTotal
if (!found && map->max_size > 0 && map->size >= map->max_size) { 85989 11 86000
if (!found && map->max_size > 0 && map->size >= map->max_size) { 835 85154 85989
if (!found && map->max_size > 0 && map->size >= map->max_size) { 708 127 835
if (!found && map->max_size > 0 && map->size >= map->max_size) { 30625 4 30629
if (!found && map->max_size > 0 && map->size >= map->max_size) { 278 30347 30625
if (!found && map->max_size > 0 && map->size >= map->max_size) { 182 96 278
if (!found && map->max_size > 0 && map->size >= map->max_size) { 50685 4 50689
if (!found && map->max_size > 0 && map->size >= map->max_size) { 278 50407 50685
if (!found && map->max_size > 0 && map->size >= map->max_size) { 182 96 278
if (!found && map->max_size > 0 && map->size >= map->max_size) { 80418 1 80419
if (!found && map->max_size > 0 && map->size >= map->max_size) { 203 80215 80418
if (!found && map->max_size > 0 && map->size >= map->max_size) { 181 22 203
if (!found && map->max_size > 0 && map->size >= map->max_size) { 81029 5 81034
if (!found && map->max_size > 0 && map->size >= map->max_size) { 203 80826 81029
if (!found && map->max_size > 0 && map->size >= map->max_size) { 181 22 203
if (!found && map->max_size > 0 && map->size >= map->max_size) { 450041 11 450052
if (!found && map->max_size > 0 && map->size >= map->max_size) { 43269 406772 450041
if (!found && map->max_size > 0 && map->size >= map->max_size) { 42532 737 43269
if (!found && map->max_size > 0 && map->size >= map->max_size) { 153254 2 153256
if (!found && map->max_size > 0 && map->size >= map->max_size) { 4 153250 153254
if (!found && map->max_size > 0 && map->size >= map->max_size) { 1 3 4
if (!found && map->max_size > 0 && map->size >= map->max_size) { 60314 1 60315
if (!found && map->max_size > 0 && map->size >= map->max_size) { 203 60111 60314
if (!found && map->max_size > 0 && map->size >= map->max_size) { 181 22 203
if (!found && map->max_size > 0 && map->size >= map->max_size) { 81232 1 81233
if (!found && map->max_size > 0 && map->size >= map->max_size) { 4 81228 81232
if (!found && map->max_size > 0 && map->size >= map->max_size) { 1 3 4
870 44149 HM_FN(lru_evict_one)(map);
871 /* Re-probe after eviction to find optimal insertion slot */
872 44149 index = HM_FN(find_slot_for_insert)(map, key, &found);
873 44149 ▶ if (index >= map->capacity) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (index >= map->capacity) return false; 0 708 708
if (index >= map->capacity) return false; 0 182 182
if (index >= map->capacity) return false; 0 182 182
if (index >= map->capacity) return false; 0 181 181
if (index >= map->capacity) return false; 0 181 181
if (index >= map->capacity) return false; 0 42532 42532
if (index >= map->capacity) return false; 0 1 1
if (index >= map->capacity) return false; 0 181 181
if (index >= map->capacity) return false; 0 1 1
874 }
875  
876 1073627 ▶ HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false);
Branch: 27 branches
BranchTrueFalseTotal
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 105 85895 86000
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 7 98 105
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 7 7
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 4 30625 30629
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 4 0 4
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 4 4
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 4 50685 50689
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 4 0 4
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 4 4
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 80419 80419
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 81034 81034
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 115 449937 450052
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 12 103 115
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 12 12
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 1 153255 153256
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 1 0 1
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 1 1
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 60315 60315
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 81233 81233
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 0 0
877  
878 #ifdef HM_VALUE_IS_STR
879 221768 char* new_val = NULL;
880 221768 uint32_t new_val_len = 0;
881 221768 ▶ if (value && val_len > 0) {
Branch: 6 branches
BranchTrueFalseTotal
if (value && val_len > 0) { 80419 0 80419
if (value && val_len > 0) { 80418 1 80419
if (value && val_len > 0) { 81034 0 81034
if (value && val_len > 0) { 81033 1 81034
if (value && val_len > 0) { 60315 0 60315
if (value && val_len > 0) { 60315 0 60315
882 221766 new_val = (char*)malloc(val_len + 1);
883 221766 ▶ if (!new_val) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (!new_val) return false; 0 80418 80418
if (!new_val) return false; 0 81033 81033
if (!new_val) return false; 0 60315 60315
884 221766 memcpy(new_val, value, val_len);
885 221766 new_val[val_len] = '\0';
886 221766 ▶ new_val_len = HM_PACK_LEN(val_len, val_utf8);
Branch: 3 branches
BranchTrueFalseTotal
new_val_len = HM_PACK_LEN(val_len, val_utf8); 1 80417 80418
new_val_len = HM_PACK_LEN(val_len, val_utf8); 102 80931 81033
new_val_len = HM_PACK_LEN(val_len, val_utf8); 1 60314 60315
887 0 ▶ } else if (value) {
Branch: 3 branches
BranchTrueFalseTotal
} else if (value) { 1 0 1
} else if (value) { 1 0 1
} else if (value) { 0 0 0
888 0 new_val = (char*)malloc(1);
889 0 ▶ if (!new_val) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (!new_val) return false; 0 1 1
if (!new_val) return false; 0 1 1
if (!new_val) return false; 0 0 0
890 0 new_val[0] = '\0';
891 0 ▶ new_val_len = HM_PACK_LEN(0, val_utf8);
Branch: 3 branches
BranchTrueFalseTotal
new_val_len = HM_PACK_LEN(0, val_utf8); 0 1 1
new_val_len = HM_PACK_LEN(0, val_utf8); 0 1 1
new_val_len = HM_PACK_LEN(0, val_utf8); 0 0 0
892 }
893 #endif
894  
895 1073627 ▶ if (found) {
Branch: 9 branches
BranchTrueFalseTotal
if (found) { 11 85989 86000
if (found) { 4 30625 30629
if (found) { 4 50685 50689
if (found) { 1 80418 80419
if (found) { 5 81029 81034
if (found) { 450041 11 450052
if (found) { 153254 2 153256
if (found) { 1 60314 60315
if (found) { 81232 1 81233
896 #ifdef HM_VALUE_IS_STR
897 7 ▶ if (map->nodes[index].value) free(map->nodes[index].value);
Branch: 3 branches
BranchTrueFalseTotal
if (map->nodes[index].value) free(map->nodes[index].value); 1 0 1
if (map->nodes[index].value) free(map->nodes[index].value); 5 0 5
if (map->nodes[index].value) free(map->nodes[index].value); 1 0 1
898 #elif defined(HM_VALUE_IS_SV)
899 19 ▶ if (map->nodes[index].value && map->free_value_fn)
Branch: 6 branches
BranchTrueFalseTotal
if (map->nodes[index].value && map->free_value_fn) 11 0 11
if (map->nodes[index].value && map->free_value_fn) 11 0 11
if (map->nodes[index].value && map->free_value_fn) 4 0 4
if (map->nodes[index].value && map->free_value_fn) 4 0 4
if (map->nodes[index].value && map->free_value_fn) 4 0 4
if (map->nodes[index].value && map->free_value_fn) 4 0 4
900 19 map->free_value_fn(map->nodes[index].value);
901 #endif
902 } else {
903 1073587 ▶ if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) {
Branch: 9 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 2166 83823 85989
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 83 30542 30625
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 83 50602 50685
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 1887 78531 80418
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 1886 79143 81029
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 51093 398948 450041
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 7226 146028 153254
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 1886 58428 60314
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 3609 77623 81232
904 69919 map->tombstones--;
905 }
906 1073587 map->size++;
907 1073587 map->nodes[index].key = key;
908 }
909  
910 #ifdef HM_VALUE_IS_STR
911 221768 map->nodes[index].value = new_val;
912 221768 map->nodes[index].val_len = new_val_len;
913 #else
914 851859 map->nodes[index].value = value;
915 #endif
916  
917 1073627 ▶ if (HM_UNLIKELY(map->lru_prev)) {
Branch: 9 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) { 836 85164 86000
if (HM_UNLIKELY(map->lru_prev)) { 278 30351 30629
if (HM_UNLIKELY(map->lru_prev)) { 278 50411 50689
if (HM_UNLIKELY(map->lru_prev)) { 203 80216 80419
if (HM_UNLIKELY(map->lru_prev)) { 203 80831 81034
if (HM_UNLIKELY(map->lru_prev)) { 43273 406779 450052
if (HM_UNLIKELY(map->lru_prev)) { 4 153252 153256
if (HM_UNLIKELY(map->lru_prev)) { 203 60112 60315
if (HM_UNLIKELY(map->lru_prev)) { 4 81229 81233
918 45282 ▶ if (found) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 9 branches
BranchTrueFalseTotal
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 1 835 836
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 278 278
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 278 278
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 203 203
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 203 203
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 4 43269 43273
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 4 4
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 203 203
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 4 4
919 45277 else HM_FN(lru_push_front)(map, (uint32_t)index);
920 }
921 1073627 ▶ if (map->expires_at) {
Branch: 9 branches
BranchTrueFalseTotal
if (map->expires_at) { 215 85785 86000
if (map->expires_at) { 13 30616 30629
if (map->expires_at) { 13 50676 50689
if (map->expires_at) { 0 80419 80419
if (map->expires_at) { 1 81033 81034
if (map->expires_at) { 209 449843 450052
if (map->expires_at) { 1 153255 153256
if (map->expires_at) { 0 60315 60315
if (map->expires_at) { 1 81232 81233
922 0 ▶ uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl;
Branch: 9 branches
BranchTrueFalseTotal
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 110 105 215
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 9 4 13
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 9 4 13
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 0 0 0
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 1 0 1
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 94 115 209
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 0 1 1
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 0 0 0
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 1 0 1
923 0 ▶ if (ttl > 0)
Branch: 9 branches
BranchTrueFalseTotal
if (ttl > 0) 207 8 215
if (ttl > 0) 5 8 13
if (ttl > 0) 5 8 13
if (ttl > 0) 0 0 0
if (ttl > 0) 1 0 1
if (ttl > 0) 206 3 209
if (ttl > 0) 1 0 1
if (ttl > 0) 0 0 0
if (ttl > 0) 1 0 1
924 0 map->expires_at[index] = hm_expiry_at(ttl);
925 else
926 0 map->expires_at[index] = 0;
927 }
928  
929 1073627 return true;
930 }
931  
932 #else /* string keys */
933  
934 408752 static bool HM_FN(put)(HM_MAP_TYPE* map,
935 const char* key, uint32_t key_len, uint32_t key_hash, bool key_utf8,
936 #ifdef HM_VALUE_IS_STR
937 const char* value, uint32_t val_len, bool val_utf8,
938 #elif defined(HM_VALUE_IS_SV)
939 void* value,
940 #else
941 HM_INT_TYPE value,
942 #endif
943 uint32_t entry_ttl) {
944 408752 ▶ if (!map || !key) return false;
Branch: 10 branches
BranchTrueFalseTotal
if (!map || !key) return false; 82372 0 82372
if (!map || !key) return false; 0 82372 82372
if (!map || !key) return false; 80236 0 80236
if (!map || !key) return false; 0 80236 80236
if (!map || !key) return false; 85724 0 85724
if (!map || !key) return false; 0 85724 85724
if (!map || !key) return false; 80284 0 80284
if (!map || !key) return false; 0 80284 80284
if (!map || !key) return false; 80136 0 80136
if (!map || !key) return false; 0 80136 80136
945  
946 408752 ▶ HM_ENSURE_CAPACITY(map, false);
Branch: 30 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, false); 113 82259 82372
HM_ENSURE_CAPACITY(map, false); 6 107 113
HM_ENSURE_CAPACITY(map, false); 113 0 113
HM_ENSURE_CAPACITY(map, false); 18 95 113
HM_ENSURE_CAPACITY(map, false); 0 18 18
HM_ENSURE_CAPACITY(map, false); 0 95 95
HM_ENSURE_CAPACITY(map, false); 31 80205 80236
HM_ENSURE_CAPACITY(map, false); 0 31 31
HM_ENSURE_CAPACITY(map, false); 31 0 31
HM_ENSURE_CAPACITY(map, false); 0 31 31
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 31 31
HM_ENSURE_CAPACITY(map, false); 132 85592 85724
HM_ENSURE_CAPACITY(map, false); 18 114 132
HM_ENSURE_CAPACITY(map, false); 132 0 132
HM_ENSURE_CAPACITY(map, false); 10 122 132
HM_ENSURE_CAPACITY(map, false); 0 10 10
HM_ENSURE_CAPACITY(map, false); 0 122 122
HM_ENSURE_CAPACITY(map, false); 32 80252 80284
HM_ENSURE_CAPACITY(map, false); 0 32 32
HM_ENSURE_CAPACITY(map, false); 32 0 32
HM_ENSURE_CAPACITY(map, false); 0 32 32
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 32 32
HM_ENSURE_CAPACITY(map, false); 29 80107 80136
HM_ENSURE_CAPACITY(map, false); 0 29 29
HM_ENSURE_CAPACITY(map, false); 29 0 29
HM_ENSURE_CAPACITY(map, false); 0 29 29
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 29 29
947  
948 bool found;
949 408752 size_t index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
950 408752 ▶ if (index >= map->capacity) return false;
Branch: 5 branches
BranchTrueFalseTotal
if (index >= map->capacity) return false; 0 82372 82372
if (index >= map->capacity) return false; 0 80236 80236
if (index >= map->capacity) return false; 0 85724 85724
if (index >= map->capacity) return false; 0 80284 80284
if (index >= map->capacity) return false; 0 80136 80136
951  
952 408752 ▶ if (!found && map->max_size > 0 && map->size >= map->max_size) {
Branch: 15 branches
BranchTrueFalseTotal
if (!found && map->max_size > 0 && map->size >= map->max_size) { 82358 14 82372
if (!found && map->max_size > 0 && map->size >= map->max_size) { 679 81679 82358
if (!found && map->max_size > 0 && map->size >= map->max_size) { 522 157 679
if (!found && map->max_size > 0 && map->size >= map->max_size) { 80230 6 80236
if (!found && map->max_size > 0 && map->size >= map->max_size) { 4 80226 80230
if (!found && map->max_size > 0 && map->size >= map->max_size) { 1 3 4
if (!found && map->max_size > 0 && map->size >= map->max_size) { 85707 17 85724
if (!found && map->max_size > 0 && map->size >= map->max_size) { 427 85280 85707
if (!found && map->max_size > 0 && map->size >= map->max_size) { 351 76 427
if (!found && map->max_size > 0 && map->size >= map->max_size) { 80276 8 80284
if (!found && map->max_size > 0 && map->size >= map->max_size) { 5 80271 80276
if (!found && map->max_size > 0 && map->size >= map->max_size) { 1 4 5
if (!found && map->max_size > 0 && map->size >= map->max_size) { 80130 6 80136
if (!found && map->max_size > 0 && map->size >= map->max_size) { 5 80125 80130
if (!found && map->max_size > 0 && map->size >= map->max_size) { 1 4 5
953 876 HM_FN(lru_evict_one)(map);
954 /* Re-probe after eviction to find optimal insertion slot */
955 876 index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
956 876 ▶ if (index >= map->capacity) return false;
Branch: 5 branches
BranchTrueFalseTotal
if (index >= map->capacity) return false; 0 522 522
if (index >= map->capacity) return false; 0 1 1
if (index >= map->capacity) return false; 0 351 351
if (index >= map->capacity) return false; 0 1 1
if (index >= map->capacity) return false; 0 1 1
957 }
958  
959 408752 ▶ HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false);
Branch: 15 branches
BranchTrueFalseTotal
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 6 82366 82372
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 6 0 6
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 6 6
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 1 80235 80236
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 1 0 1
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 1 1
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 107 85617 85724
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 8 99 107
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 8 8
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 80284 80284
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 1 80135 80136
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 1 0 1
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, false); 0 1 1
960  
961 #ifdef HM_VALUE_IS_STR
962 85724 char* new_val = NULL;
963 85724 uint32_t new_val_len = 0;
964 85724 ▶ if (value && val_len > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (value && val_len > 0) { 85724 0 85724
if (value && val_len > 0) { 85723 1 85724
965 85723 new_val = (char*)malloc(val_len + 1);
966 85723 ▶ if (!new_val) return false;
Branch: 1 branch
BranchTrueFalseTotal
if (!new_val) return false; 0 85723 85723
967 85723 memcpy(new_val, value, val_len);
968 85723 new_val[val_len] = '\0';
969 85723 ▶ new_val_len = HM_PACK_LEN(val_len, val_utf8);
Branch: 1 branch
BranchTrueFalseTotal
new_val_len = HM_PACK_LEN(val_len, val_utf8); 106 85617 85723
970 1 ▶ } else if (value) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (value) { 1 0 1
971 1 new_val = (char*)malloc(1);
972 1 ▶ if (!new_val) return false;
Branch: 1 branch
BranchTrueFalseTotal
if (!new_val) return false; 0 1 1
973 1 new_val[0] = '\0';
974 1 ▶ new_val_len = HM_PACK_LEN(0, val_utf8);
Branch: 1 branch
BranchTrueFalseTotal
new_val_len = HM_PACK_LEN(0, val_utf8); 0 1 1
975 }
976 #endif
977  
978 408752 ▶ if (found) {
Branch: 5 branches
BranchTrueFalseTotal
if (found) { 14 82358 82372
if (found) { 6 80230 80236
if (found) { 17 85707 85724
if (found) { 8 80276 80284
if (found) { 6 80130 80136
979 #ifdef HM_VALUE_IS_STR
980 17 ▶ if (map->nodes[index].value) free(map->nodes[index].value);
Branch: 1 branch
BranchTrueFalseTotal
if (map->nodes[index].value) free(map->nodes[index].value); 17 0 17
981 #elif defined(HM_VALUE_IS_SV)
982 14 ▶ if (map->nodes[index].value && map->free_value_fn)
Branch: 2 branches
BranchTrueFalseTotal
if (map->nodes[index].value && map->free_value_fn) 14 0 14
if (map->nodes[index].value && map->free_value_fn) 14 0 14
983 14 map->free_value_fn(map->nodes[index].value);
984 #endif
985 51 ▶ map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8);
Branch: 5 branches
BranchTrueFalseTotal
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 1 13 14
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 1 5 6
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 1 16 17
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 1 7 8
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 1 5 6
986 } else {
987 408701 char* new_key = (char*)malloc(key_len + 1);
988 408701 ▶ if (!new_key) {
Branch: 5 branches
BranchTrueFalseTotal
if (!new_key) { 0 82358 82358
if (!new_key) { 0 80230 80230
if (!new_key) { 0 85707 85707
if (!new_key) { 0 80276 80276
if (!new_key) { 0 80130 80130
989 #ifdef HM_VALUE_IS_STR
990 0 free(new_val);
991 #endif
992 0 return false;
993 }
994 408701 memcpy(new_key, key, key_len);
995 408701 new_key[key_len] = '\0';
996 408701 ▶ if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) {
Branch: 5 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 2023 80335 82358
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 1804 78426 80230
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 1974 83733 85707
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 1804 78472 80276
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) { 1804 78326 80130
997 9409 map->tombstones--;
998 }
999 408701 map->size++;
1000 408701 map->nodes[index].key = new_key;
1001 408701 ▶ map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8);
Branch: 5 branches
BranchTrueFalseTotal
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 3 82355 82358
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 3 80227 80230
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 112 85595 85707
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 3 80273 80276
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 3 80127 80130
1002 408701 map->nodes[index].key_hash = key_hash;
1003 }
1004  
1005 #ifdef HM_VALUE_IS_STR
1006 85724 map->nodes[index].value = new_val;
1007 85724 map->nodes[index].val_len = new_val_len;
1008 #else
1009 323028 map->nodes[index].value = value;
1010 #endif
1011  
1012 408752 ▶ if (HM_UNLIKELY(map->lru_prev)) {
Branch: 5 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) { 679 81693 82372
if (HM_UNLIKELY(map->lru_prev)) { 4 80232 80236
if (HM_UNLIKELY(map->lru_prev)) { 427 85297 85724
if (HM_UNLIKELY(map->lru_prev)) { 5 80279 80284
if (HM_UNLIKELY(map->lru_prev)) { 5 80131 80136
1013 1120 ▶ if (found) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 5 branches
BranchTrueFalseTotal
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 679 679
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 4 4
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 427 427
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 5 5
if (found) HM_FN(lru_promote)(map, (uint32_t)index); 0 5 5
1014 1120 else HM_FN(lru_push_front)(map, (uint32_t)index);
1015 }
1016 408752 ▶ if (map->expires_at) {
Branch: 5 branches
BranchTrueFalseTotal
if (map->expires_at) { 216 82156 82372
if (map->expires_at) { 1 80235 80236
if (map->expires_at) { 419 85305 85724
if (map->expires_at) { 1 80283 80284
if (map->expires_at) { 2 80134 80136
1017 639 ▶ uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl;
Branch: 5 branches
BranchTrueFalseTotal
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 210 6 216
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 0 1 1
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 312 107 419
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 1 0 1
uint32_t ttl = entry_ttl > 0 ? entry_ttl : map->default_ttl; 1 1 2
1018 639 ▶ if (ttl > 0)
Branch: 5 branches
BranchTrueFalseTotal
if (ttl > 0) 208 8 216
if (ttl > 0) 1 0 1
if (ttl > 0) 417 2 419
if (ttl > 0) 1 0 1
if (ttl > 0) 2 0 2
1019 629 map->expires_at[index] = hm_expiry_at(ttl);
1020 else
1021 0 map->expires_at[index] = 0;
1022 }
1023  
1024 408752 return true;
1025 }
1026  
1027 #endif /* HM_KEY_IS_INT */
1028  
1029 /* ---- get ---- */
1030  
1031 #ifdef HM_KEY_IS_INT
1032  
1033 #ifdef HM_VALUE_IS_STR
1034 130042 static bool HM_FN(get)(HM_MAP_TYPE* map, HM_INT_TYPE key,
1035 const char** out_value, uint32_t* out_len, bool* out_utf8) {
1036 130042 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return false; 50012 0 50012
if (!map || HM_IS_RESERVED_KEY(key)) return false; 50011 1 50012
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 50011 50011
if (!map || HM_IS_RESERVED_KEY(key)) return false; 50018 0 50018
if (!map || HM_IS_RESERVED_KEY(key)) return false; 50017 1 50018
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 50017 50017
if (!map || HM_IS_RESERVED_KEY(key)) return false; 30012 0 30012
if (!map || HM_IS_RESERVED_KEY(key)) return false; 30011 1 30012
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 30011 30011
1037  
1038 130039 size_t index = HM_FN(find_node)(map, key);
1039 130039 ▶ if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 50011 0 50011
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 2 50009 50011
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 50017 0 50017
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 3 50014 50017
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 30011 0 30011
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 3 30008 30011
1040  
1041 130031 ▶ HM_TTL_CHECK_EXPIRED(map, index, false);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, false); 0 50009 50009
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 2 50012 50014
HM_TTL_CHECK_EXPIRED(map, index, false); 2 0 2
HM_TTL_CHECK_EXPIRED(map, index, false); 1 1 2
HM_TTL_CHECK_EXPIRED(map, index, false); 0 30008 30008
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
1042  
1043 130030 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 50009 50009
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 1 50012 50013
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 30008 30008
1044  
1045 130030 *out_value = map->nodes[index].value;
1046 130030 *out_len = HM_UNPACK_LEN(map->nodes[index].val_len);
1047 130030 *out_utf8 = HM_UNPACK_UTF8(map->nodes[index].val_len);
1048 130030 return true;
1049 }
1050 #elif defined(HM_VALUE_IS_SV)
1051 132937 static bool HM_FN(get)(HM_MAP_TYPE* map, HM_INT_TYPE key, void** out_value) {
1052 132937 ▶ if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 52855 0 52855
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 52855 0 52855
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 52854 1 52855
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 52854 52854
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 30041 0 30041
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 30041 0 30041
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 30041 0 30041
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 30041 30041
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 50041 0 50041
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 50041 0 50041
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 50041 0 50041
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 50041 50041
1053  
1054 132936 size_t index = HM_FN(find_node)(map, key);
1055 132936 ▶ if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 52854 0 52854
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 4 52850 52854
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 30041 0 30041
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 3 30038 30041
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 50041 0 50041
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 3 50038 50041
1056  
1057 132926 ▶ HM_TTL_CHECK_EXPIRED(map, index, false);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, false); 26 52824 52850
HM_TTL_CHECK_EXPIRED(map, index, false); 6 20 26
HM_TTL_CHECK_EXPIRED(map, index, false); 2 4 6
HM_TTL_CHECK_EXPIRED(map, index, false); 25 30013 30038
HM_TTL_CHECK_EXPIRED(map, index, false); 5 20 25
HM_TTL_CHECK_EXPIRED(map, index, false); 1 4 5
HM_TTL_CHECK_EXPIRED(map, index, false); 25 50013 50038
HM_TTL_CHECK_EXPIRED(map, index, false); 5 20 25
HM_TTL_CHECK_EXPIRED(map, index, false); 1 4 5
1058  
1059 132922 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 4 52844 52848
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 2 30035 30037
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 2 50035 50037
1060  
1061 132922 *out_value = map->nodes[index].value;
1062 132922 return true;
1063 }
1064 #else
1065 185926 static bool HM_FN(get)(HM_MAP_TYPE* map, HM_INT_TYPE key, HM_INT_TYPE* out_value) {
1066 185926 ▶ if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 103098 0 103098
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 103098 0 103098
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 103097 1 103098
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 103097 103097
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 52812 0 52812
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 52812 0 52812
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 52811 1 52812
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 52811 52811
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 30016 0 30016
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 30016 0 30016
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 30015 1 30016
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 30015 30015
1067  
1068 185923 size_t index = HM_FN(find_node)(map, key);
1069 185923 ▶ if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 103097 0 103097
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 19 103078 103097
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 52811 0 52811
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 3 52808 52811
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 30015 0 30015
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 4 30011 30015
1070  
1071 185897 ▶ HM_TTL_CHECK_EXPIRED(map, index, false);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, false); 34 103044 103078
HM_TTL_CHECK_EXPIRED(map, index, false); 28 6 34
HM_TTL_CHECK_EXPIRED(map, index, false); 13 15 28
HM_TTL_CHECK_EXPIRED(map, index, false); 2 52806 52808
HM_TTL_CHECK_EXPIRED(map, index, false); 2 0 2
HM_TTL_CHECK_EXPIRED(map, index, false); 1 1 2
HM_TTL_CHECK_EXPIRED(map, index, false); 2 30009 30011
HM_TTL_CHECK_EXPIRED(map, index, false); 2 0 2
HM_TTL_CHECK_EXPIRED(map, index, false); 1 1 2
1072  
1073 185882 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 212 102853 103065
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 52807 52807
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 30010 30010
1074  
1075 185882 *out_value = map->nodes[index].value;
1076 185882 return true;
1077 }
1078 #endif
1079  
1080 #else /* string keys */
1081  
1082 #ifdef HM_VALUE_IS_STR
1083 52866 static bool HM_FN(get)(HM_MAP_TYPE* map,
1084 const char* key, uint32_t key_len, uint32_t key_hash,
1085 const char** out_value, uint32_t* out_len, bool* out_utf8) {
1086 52866 ▶ if (!map || !key) return false;
Branch: 2 branches
BranchTrueFalseTotal
if (!map || !key) return false; 52866 0 52866
if (!map || !key) return false; 0 52866 52866
1087  
1088 52866 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1089 52866 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 2 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 52866 0 52866
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 5 52861 52866
1090  
1091 52861 ▶ HM_TTL_CHECK_EXPIRED(map, index, false);
Branch: 3 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, false); 9 52852 52861
HM_TTL_CHECK_EXPIRED(map, index, false); 5 4 9
HM_TTL_CHECK_EXPIRED(map, index, false); 3 2 5
1092  
1093 52858 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 1 branch
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 3 52855 52858
1094  
1095 52858 *out_value = map->nodes[index].value;
1096 52858 *out_len = HM_UNPACK_LEN(map->nodes[index].val_len);
1097 52858 *out_utf8 = HM_UNPACK_UTF8(map->nodes[index].val_len);
1098 52858 return true;
1099 }
1100 #elif defined(HM_VALUE_IS_SV)
1101 50065 static bool HM_FN(get)(HM_MAP_TYPE* map,
1102 const char* key, uint32_t key_len, uint32_t key_hash,
1103 void** out_value) {
1104 50065 ▶ if (!map || !key || !out_value) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (!map || !key || !out_value) return false; 50065 0 50065
if (!map || !key || !out_value) return false; 50065 0 50065
if (!map || !key || !out_value) return false; 0 50065 50065
1105  
1106 50065 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1107 50065 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 2 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 50065 0 50065
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 3 50062 50065
1108  
1109 50062 ▶ HM_TTL_CHECK_EXPIRED(map, index, false);
Branch: 3 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, false); 26 50036 50062
HM_TTL_CHECK_EXPIRED(map, index, false); 6 20 26
HM_TTL_CHECK_EXPIRED(map, index, false); 2 4 6
1110  
1111 50060 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 1 branch
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 2 50058 50060
1112  
1113 50060 *out_value = map->nodes[index].value;
1114 50060 return true;
1115 }
1116 #else
1117 150078 static bool HM_FN(get)(HM_MAP_TYPE* map,
1118 const char* key, uint32_t key_len, uint32_t key_hash,
1119 HM_INT_TYPE* out_value) {
1120 150078 ▶ if (!map || !key || !out_value) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (!map || !key || !out_value) return false; 50022 0 50022
if (!map || !key || !out_value) return false; 50022 0 50022
if (!map || !key || !out_value) return false; 0 50022 50022
if (!map || !key || !out_value) return false; 50033 0 50033
if (!map || !key || !out_value) return false; 50033 0 50033
if (!map || !key || !out_value) return false; 0 50033 50033
if (!map || !key || !out_value) return false; 50023 0 50023
if (!map || !key || !out_value) return false; 50023 0 50023
if (!map || !key || !out_value) return false; 0 50023 50023
1121  
1122 150078 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1123 150078 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 50022 0 50022
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 2 50020 50022
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 50033 0 50033
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 2 50031 50033
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 50023 0 50023
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 2 50021 50023
1124  
1125 150072 ▶ HM_TTL_CHECK_EXPIRED(map, index, false);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, false); 2 50018 50020
HM_TTL_CHECK_EXPIRED(map, index, false); 2 0 2
HM_TTL_CHECK_EXPIRED(map, index, false); 1 1 2
HM_TTL_CHECK_EXPIRED(map, index, false); 1 50030 50031
HM_TTL_CHECK_EXPIRED(map, index, false); 1 0 1
HM_TTL_CHECK_EXPIRED(map, index, false); 1 0 1
HM_TTL_CHECK_EXPIRED(map, index, false); 3 50018 50021
HM_TTL_CHECK_EXPIRED(map, index, false); 3 0 3
HM_TTL_CHECK_EXPIRED(map, index, false); 2 1 3
1126  
1127 150068 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 50019 50019
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 1 50029 50030
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 1 50018 50019
1128  
1129 150068 *out_value = map->nodes[index].value;
1130 150068 return true;
1131 }
1132 #endif
1133  
1134 #endif /* HM_KEY_IS_INT */
1135  
1136 /* ---- exists ---- */
1137  
1138 #ifdef HM_KEY_IS_INT
1139  
1140 14535 static bool HM_FN(exists)(HM_MAP_TYPE* map, HM_INT_TYPE key) {
1141 14535 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return false;
Branch: 27 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return false; 4834 0 4834
if (!map || HM_IS_RESERVED_KEY(key)) return false; 4834 0 4834
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 4834 4834
if (!map || HM_IS_RESERVED_KEY(key)) return false; 4833 0 4833
if (!map || HM_IS_RESERVED_KEY(key)) return false; 4833 0 4833
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 4833 4833
if (!map || HM_IS_RESERVED_KEY(key)) return false; 4833 0 4833
if (!map || HM_IS_RESERVED_KEY(key)) return false; 4833 0 4833
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 4833 4833
if (!map || HM_IS_RESERVED_KEY(key)) return false; 3 0 3
if (!map || HM_IS_RESERVED_KEY(key)) return false; 2 1 3
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 2 2
if (!map || HM_IS_RESERVED_KEY(key)) return false; 3 0 3
if (!map || HM_IS_RESERVED_KEY(key)) return false; 2 1 3
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 2 2
if (!map || HM_IS_RESERVED_KEY(key)) return false; 18 0 18
if (!map || HM_IS_RESERVED_KEY(key)) return false; 17 1 18
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 17 17
if (!map || HM_IS_RESERVED_KEY(key)) return false; 3 0 3
if (!map || HM_IS_RESERVED_KEY(key)) return false; 2 1 3
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 2 2
if (!map || HM_IS_RESERVED_KEY(key)) return false; 4 0 4
if (!map || HM_IS_RESERVED_KEY(key)) return false; 3 1 4
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 3 3
if (!map || HM_IS_RESERVED_KEY(key)) return false; 4 0 4
if (!map || HM_IS_RESERVED_KEY(key)) return false; 3 1 4
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 3 3
1142 14529 size_t index = HM_FN(find_node)(map, key);
1143 14529 ▶ if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false;
Branch: 18 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 4834 0 4834
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 1 4833 4834
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 4833 0 4833
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 1 4832 4833
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 4833 0 4833
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 1 4832 4833
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 2 0 2
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 1 1 2
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 2 0 2
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 1 1 2
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 17 0 17
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 8 9 17
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 2 0 2
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 1 1 2
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 3 0 3
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 1 2 3
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 3 0 3
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 1 2 3
1144  
1145 14513 ▶ HM_TTL_CHECK_EXPIRED(map, index, false);
Branch: 27 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, false); 0 4833 4833
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 4832 4832
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 4832 4832
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 3 6 9
HM_TTL_CHECK_EXPIRED(map, index, false); 3 0 3
HM_TTL_CHECK_EXPIRED(map, index, false); 2 1 3
HM_TTL_CHECK_EXPIRED(map, index, false); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 2 2
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 2 2
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
1146 14511 return true;
1147 }
1148  
1149 #else
1150  
1151 4845 static bool HM_FN(exists)(HM_MAP_TYPE* map,
1152 const char* key, uint32_t key_len, uint32_t key_hash) {
1153 4845 ▶ if (!map || !key) return false;
Branch: 10 branches
BranchTrueFalseTotal
if (!map || !key) return false; 4835 0 4835
if (!map || !key) return false; 0 4835 4835
if (!map || !key) return false; 2 0 2
if (!map || !key) return false; 0 2 2
if (!map || !key) return false; 2 0 2
if (!map || !key) return false; 0 2 2
if (!map || !key) return false; 2 0 2
if (!map || !key) return false; 0 2 2
if (!map || !key) return false; 4 0 4
if (!map || !key) return false; 0 4 4
1154 4845 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1155 4845 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 10 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 4835 0 4835
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 4834 4835
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 2 0 2
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 1 2
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 2 0 2
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 1 2
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 2 0 2
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 1 2
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 4 0 4
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 3 4
1156  
1157 4840 ▶ HM_TTL_CHECK_EXPIRED(map, index, false);
Branch: 15 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, false); 0 4834 4834
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 3 3
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, false); 0 0 0
1158 4840 return true;
1159 }
1160  
1161 #endif
1162  
1163 /* ---- remove ---- */
1164  
1165 #ifdef HM_KEY_IS_INT
1166  
1167 891276 static bool HM_FN(remove)(HM_MAP_TYPE* map, HM_INT_TYPE key) {
1168 891276 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return false;
Branch: 27 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return false; 80711 0 80711
if (!map || HM_IS_RESERVED_KEY(key)) return false; 80711 0 80711
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 80711 80711
if (!map || HM_IS_RESERVED_KEY(key)) return false; 30007 0 30007
if (!map || HM_IS_RESERVED_KEY(key)) return false; 30007 0 30007
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 30007 30007
if (!map || HM_IS_RESERVED_KEY(key)) return false; 50007 0 50007
if (!map || HM_IS_RESERVED_KEY(key)) return false; 50007 0 50007
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 50007 50007
if (!map || HM_IS_RESERVED_KEY(key)) return false; 80006 0 80006
if (!map || HM_IS_RESERVED_KEY(key)) return false; 80005 1 80006
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 80004 80005
if (!map || HM_IS_RESERVED_KEY(key)) return false; 80106 0 80106
if (!map || HM_IS_RESERVED_KEY(key)) return false; 80105 1 80106
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 80104 80105
if (!map || HM_IS_RESERVED_KEY(key)) return false; 280222 0 280222
if (!map || HM_IS_RESERVED_KEY(key)) return false; 280221 1 280222
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 280221 280221
if (!map || HM_IS_RESERVED_KEY(key)) return false; 150204 0 150204
if (!map || HM_IS_RESERVED_KEY(key)) return false; 150203 1 150204
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 150203 150203
if (!map || HM_IS_RESERVED_KEY(key)) return false; 60006 0 60006
if (!map || HM_IS_RESERVED_KEY(key)) return false; 60005 1 60006
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 60004 60005
if (!map || HM_IS_RESERVED_KEY(key)) return false; 80007 0 80007
if (!map || HM_IS_RESERVED_KEY(key)) return false; 80006 1 80007
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 80006 80006
1169  
1170 891267 size_t index = HM_FN(find_node)(map, key);
1171 891267 ▶ if (index >= map->capacity || map->nodes[index].key != key) return false;
Branch: 18 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key != key) return false; 80711 0 80711
if (index >= map->capacity || map->nodes[index].key != key) return false; 4 80707 80711
if (index >= map->capacity || map->nodes[index].key != key) return false; 30007 0 30007
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 30006 30007
if (index >= map->capacity || map->nodes[index].key != key) return false; 50007 0 50007
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 50006 50007
if (index >= map->capacity || map->nodes[index].key != key) return false; 80004 0 80004
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 80003 80004
if (index >= map->capacity || map->nodes[index].key != key) return false; 80104 0 80104
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 80103 80104
if (index >= map->capacity || map->nodes[index].key != key) return false; 280221 0 280221
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 280220 280221
if (index >= map->capacity || map->nodes[index].key != key) return false; 150203 0 150203
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 150202 150203
if (index >= map->capacity || map->nodes[index].key != key) return false; 60004 0 60004
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 60003 60004
if (index >= map->capacity || map->nodes[index].key != key) return false; 80006 0 80006
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 80005 80006
1172  
1173 891255 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 27 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 2 80705 80707
HM_TTL_CHECK_EXPIRED(map, index, true); 0 2 2
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 2 30004 30006
HM_TTL_CHECK_EXPIRED(map, index, true); 0 2 2
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 2 50004 50006
HM_TTL_CHECK_EXPIRED(map, index, true); 0 2 2
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 80003 80003
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 80103 80103
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 2 280218 280220
HM_TTL_CHECK_EXPIRED(map, index, true); 2 0 2
HM_TTL_CHECK_EXPIRED(map, index, true); 1 1 2
HM_TTL_CHECK_EXPIRED(map, index, true); 0 150202 150202
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 60003 60003
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 80005 80005
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1174  
1175 891254 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index);
Branch: 9 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 1 80706 80707
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 30006 30006
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 50006 50006
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 80003 80003
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 80103 80103
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 5 280214 280219
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 150202 150202
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 60003 60003
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 80005 80005
1176 891254 HM_FN(tombstone_at)(map, index);
1177 891254 ▶ HM_MAYBE_COMPACT(map);
Branch: 36 branches
BranchTrueFalseTotal
HM_MAYBE_COMPACT(map); 80704 3 80707
HM_MAYBE_COMPACT(map); 80689 15 80704
HM_MAYBE_COMPACT(map); 11359 69330 80689
HM_MAYBE_COMPACT(map); 28 11331 11359
HM_MAYBE_COMPACT(map); 30006 0 30006
HM_MAYBE_COMPACT(map); 30004 2 30006
HM_MAYBE_COMPACT(map); 4097 25907 30004
HM_MAYBE_COMPACT(map); 2 4095 4097
HM_MAYBE_COMPACT(map); 50006 0 50006
HM_MAYBE_COMPACT(map); 50004 2 50006
HM_MAYBE_COMPACT(map); 8193 41811 50004
HM_MAYBE_COMPACT(map); 2 8191 8193
HM_MAYBE_COMPACT(map); 80000 3 80003
HM_MAYBE_COMPACT(map); 79996 4 80000
HM_MAYBE_COMPACT(map); 11268 68728 79996
HM_MAYBE_COMPACT(map); 8 11260 11268
HM_MAYBE_COMPACT(map); 80100 3 80103
HM_MAYBE_COMPACT(map); 80094 6 80100
HM_MAYBE_COMPACT(map); 11286 68808 80094
HM_MAYBE_COMPACT(map); 12 11274 11286
HM_MAYBE_COMPACT(map); 280215 4 280219
HM_MAYBE_COMPACT(map); 280203 12 280215
HM_MAYBE_COMPACT(map); 44041 236162 280203
HM_MAYBE_COMPACT(map); 17 44024 44041
HM_MAYBE_COMPACT(map); 150197 5 150202
HM_MAYBE_COMPACT(map); 150189 8 150197
HM_MAYBE_COMPACT(map); 18438 131751 150189
HM_MAYBE_COMPACT(map); 12 18426 18438
HM_MAYBE_COMPACT(map); 60000 3 60003
HM_MAYBE_COMPACT(map); 59996 4 60000
HM_MAYBE_COMPACT(map); 7172 52824 59996
HM_MAYBE_COMPACT(map); 8 7164 7172
HM_MAYBE_COMPACT(map); 80000 5 80005
HM_MAYBE_COMPACT(map); 79992 8 80000
HM_MAYBE_COMPACT(map); 9222 70770 79992
HM_MAYBE_COMPACT(map); 12 9210 9222
1178 891254 return true;
1179 }
1180  
1181 #else /* string keys */
1182  
1183 401258 static bool HM_FN(remove)(HM_MAP_TYPE* map,
1184 const char* key, uint32_t key_len, uint32_t key_hash) {
1185 401258 ▶ if (!map || !key) return false;
Branch: 10 branches
BranchTrueFalseTotal
if (!map || !key) return false; 80512 0 80512
if (!map || !key) return false; 0 80512 80512
if (!map || !key) return false; 80010 0 80010
if (!map || !key) return false; 0 80010 80010
if (!map || !key) return false; 80715 0 80715
if (!map || !key) return false; 0 80715 80715
if (!map || !key) return false; 80011 0 80011
if (!map || !key) return false; 0 80011 80011
if (!map || !key) return false; 80010 0 80010
if (!map || !key) return false; 0 80010 80010
1186  
1187 401258 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1188 401258 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 10 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 80512 0 80512
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 80511 80512
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 80010 0 80010
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 80009 80010
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 80715 0 80715
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 80714 80715
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 80011 0 80011
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 80010 80011
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 80010 0 80010
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 80009 80010
1189  
1190 401253 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 15 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 2 80509 80511
HM_TTL_CHECK_EXPIRED(map, index, true); 0 2 2
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 80009 80009
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 80714 80714
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 80010 80010
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 80009 80009
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1191  
1192 401253 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index);
Branch: 5 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 80511 80511
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 80009 80009
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 80714 80714
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 80010 80010
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 80009 80009
1193 401253 HM_FN(tombstone_at)(map, index);
1194 401253 ▶ HM_MAYBE_COMPACT(map);
Branch: 20 branches
BranchTrueFalseTotal
HM_MAYBE_COMPACT(map); 80508 3 80511
HM_MAYBE_COMPACT(map); 80488 20 80508
HM_MAYBE_COMPACT(map); 11358 69130 80488
HM_MAYBE_COMPACT(map); 28 11330 11358
HM_MAYBE_COMPACT(map); 80006 3 80009
HM_MAYBE_COMPACT(map); 79997 9 80006
HM_MAYBE_COMPACT(map); 11268 68729 79997
HM_MAYBE_COMPACT(map); 8 11260 11268
HM_MAYBE_COMPACT(map); 80711 3 80714
HM_MAYBE_COMPACT(map); 80690 21 80711
HM_MAYBE_COMPACT(map); 11358 69332 80690
HM_MAYBE_COMPACT(map); 28 11330 11358
HM_MAYBE_COMPACT(map); 80007 3 80010
HM_MAYBE_COMPACT(map); 79997 10 80007
HM_MAYBE_COMPACT(map); 11268 68729 79997
HM_MAYBE_COMPACT(map); 8 11260 11268
HM_MAYBE_COMPACT(map); 80006 3 80009
HM_MAYBE_COMPACT(map); 79996 10 80006
HM_MAYBE_COMPACT(map); 11268 68728 79996
HM_MAYBE_COMPACT(map); 8 11260 11268
1195 401253 return true;
1196 }
1197  
1198 #endif
1199  
1200 /* ---- Take (remove and return value) ---- */
1201  
1202 #ifdef HM_KEY_IS_INT
1203  
1204 #ifdef HM_VALUE_IS_STR
1205 3 static bool HM_FN(take)(HM_MAP_TYPE* map, HM_INT_TYPE key,
1206 const char** out_value, uint32_t* out_len, bool* out_utf8) {
1207 3 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 1 1
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 1 1
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 1 1
1208  
1209 3 size_t index = HM_FN(find_node)(map, key);
1210 3 ▶ if (index >= map->capacity || map->nodes[index].key != key) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 0 1
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 1 1
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 0 1
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 1 1
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 0 1
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 1 1
1211  
1212 3 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1213  
1214 3 *out_value = map->nodes[index].value;
1215 3 *out_len = HM_UNPACK_LEN(map->nodes[index].val_len);
1216 3 *out_utf8 = HM_UNPACK_UTF8(map->nodes[index].val_len);
1217 3 map->nodes[index].value = NULL; /* prevent free_node from freeing */
1218  
1219 3 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
1220 3 HM_FN(tombstone_at)(map, index);
1221 3 ▶ HM_MAYBE_COMPACT(map);
Branch: 12 branches
BranchTrueFalseTotal
HM_MAYBE_COMPACT(map); 1 0 1
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 1 0 1
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 1 0 1
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 0 0 0
1222 3 return true;
1223 }
1224 #elif defined(HM_VALUE_IS_SV)
1225 4 static bool HM_FN(take)(HM_MAP_TYPE* map, HM_INT_TYPE key, void** out_value) {
1226 4 ▶ if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 2 0 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 2 0 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 2 0 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 2 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 1 1
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 1 0 1
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 1 1
1227  
1228 4 size_t index = HM_FN(find_node)(map, key);
1229 4 ▶ if (index >= map->capacity || map->nodes[index].key != key) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key != key) return false; 2 0 2
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 1 2
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 0 1
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 1 1
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 0 1
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 1 1
1230  
1231 3 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1232  
1233 3 *out_value = map->nodes[index].value;
1234 3 map->nodes[index].value = NULL; /* transfer ownership to caller */
1235  
1236 3 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
1237 3 HM_FN(tombstone_at)(map, index);
1238 3 ▶ HM_MAYBE_COMPACT(map);
Branch: 12 branches
BranchTrueFalseTotal
HM_MAYBE_COMPACT(map); 1 0 1
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 1 0 1
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 1 0 1
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 0 0 0
1239 3 return true;
1240 }
1241 #else
1242 9 static bool HM_FN(take)(HM_MAP_TYPE* map, HM_INT_TYPE key, HM_INT_TYPE* out_value) {
1243 9 ▶ if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 5 0 5
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 5 0 5
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 5 0 5
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 5 5
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 2 0 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 2 0 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 2 0 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 2 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 2 0 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 2 0 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 2 0 2
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 2 2
1244  
1245 9 size_t index = HM_FN(find_node)(map, key);
1246 9 ▶ if (index >= map->capacity || map->nodes[index].key != key) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key != key) return false; 5 0 5
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 4 5
if (index >= map->capacity || map->nodes[index].key != key) return false; 2 0 2
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 2 2
if (index >= map->capacity || map->nodes[index].key != key) return false; 2 0 2
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 2 2
1247  
1248 8 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 1 3 4
HM_TTL_CHECK_EXPIRED(map, index, true); 1 0 1
HM_TTL_CHECK_EXPIRED(map, index, true); 1 0 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 2 2
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 2 2
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1249  
1250 7 *out_value = map->nodes[index].value;
1251  
1252 7 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 3 3
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 2 2
1253 7 HM_FN(tombstone_at)(map, index);
1254 7 ▶ HM_MAYBE_COMPACT(map);
Branch: 12 branches
BranchTrueFalseTotal
HM_MAYBE_COMPACT(map); 3 0 3
HM_MAYBE_COMPACT(map); 2 1 3
HM_MAYBE_COMPACT(map); 0 2 2
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 2 0 2
HM_MAYBE_COMPACT(map); 1 1 2
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 2 0 2
HM_MAYBE_COMPACT(map); 1 1 2
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
1255 7 return true;
1256 }
1257 #endif
1258  
1259 #else /* string keys */
1260  
1261 #ifdef HM_VALUE_IS_STR
1262 3 static bool HM_FN(take)(HM_MAP_TYPE* map,
1263 const char* key, uint32_t key_len, uint32_t key_hash,
1264 const char** out_value, uint32_t* out_len, bool* out_utf8) {
1265 3 ▶ if (!map || !key) return false;
Branch: 2 branches
BranchTrueFalseTotal
if (!map || !key) return false; 3 0 3
if (!map || !key) return false; 0 3 3
1266  
1267 3 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1268 3 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 2 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 3 0 3
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 3 3
1269  
1270 3 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 3 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 3 3
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1271  
1272 3 *out_value = map->nodes[index].value;
1273 3 *out_len = HM_UNPACK_LEN(map->nodes[index].val_len);
1274 3 *out_utf8 = HM_UNPACK_UTF8(map->nodes[index].val_len);
1275 3 map->nodes[index].value = NULL;
1276  
1277 3 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index);
Branch: 1 branch
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 3 3
1278 3 HM_FN(tombstone_at)(map, index);
1279 3 ▶ HM_MAYBE_COMPACT(map);
Branch: 4 branches
BranchTrueFalseTotal
HM_MAYBE_COMPACT(map); 3 0 3
HM_MAYBE_COMPACT(map); 2 1 3
HM_MAYBE_COMPACT(map); 0 2 2
HM_MAYBE_COMPACT(map); 0 0 0
1280 3 return true;
1281 }
1282 #elif defined(HM_VALUE_IS_SV)
1283 3 static bool HM_FN(take)(HM_MAP_TYPE* map,
1284 const char* key, uint32_t key_len, uint32_t key_hash,
1285 void** out_value) {
1286 3 ▶ if (!map || !key || !out_value) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (!map || !key || !out_value) return false; 3 0 3
if (!map || !key || !out_value) return false; 3 0 3
if (!map || !key || !out_value) return false; 0 3 3
1287  
1288 3 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1289 3 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 2 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 3 0 3
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 3 3
1290  
1291 3 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 3 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 3 3
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1292  
1293 3 *out_value = map->nodes[index].value;
1294 3 map->nodes[index].value = NULL;
1295  
1296 3 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index);
Branch: 1 branch
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 3 3
1297 3 HM_FN(tombstone_at)(map, index);
1298 3 ▶ HM_MAYBE_COMPACT(map);
Branch: 4 branches
BranchTrueFalseTotal
HM_MAYBE_COMPACT(map); 3 0 3
HM_MAYBE_COMPACT(map); 2 1 3
HM_MAYBE_COMPACT(map); 0 2 2
HM_MAYBE_COMPACT(map); 0 0 0
1299 3 return true;
1300 }
1301 #else
1302 3 static bool HM_FN(take)(HM_MAP_TYPE* map,
1303 const char* key, uint32_t key_len, uint32_t key_hash,
1304 HM_INT_TYPE* out_value) {
1305 3 ▶ if (!map || !key || !out_value) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (!map || !key || !out_value) return false; 1 0 1
if (!map || !key || !out_value) return false; 1 0 1
if (!map || !key || !out_value) return false; 0 1 1
if (!map || !key || !out_value) return false; 1 0 1
if (!map || !key || !out_value) return false; 1 0 1
if (!map || !key || !out_value) return false; 0 1 1
if (!map || !key || !out_value) return false; 1 0 1
if (!map || !key || !out_value) return false; 1 0 1
if (!map || !key || !out_value) return false; 0 1 1
1306  
1307 3 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1308 3 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 0 1
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 1 1
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 0 1
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 1 1
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 0 1
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 1 1
1309  
1310 3 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1311  
1312 3 *out_value = map->nodes[index].value;
1313  
1314 3 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_unlink)(map, (uint32_t)index); 0 1 1
1315 3 HM_FN(tombstone_at)(map, index);
1316 3 ▶ HM_MAYBE_COMPACT(map);
Branch: 12 branches
BranchTrueFalseTotal
HM_MAYBE_COMPACT(map); 1 0 1
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 1 0 1
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 1 0 1
HM_MAYBE_COMPACT(map); 0 1 1
HM_MAYBE_COMPACT(map); 0 0 0
HM_MAYBE_COMPACT(map); 0 0 0
1317 3 return true;
1318 }
1319 #endif
1320  
1321 #endif /* HM_KEY_IS_INT */
1322  
1323 /* ---- persist: remove TTL from a key ---- */
1324  
1325 #ifdef HM_KEY_IS_INT
1326 0 static bool HM_FN(persist)(HM_MAP_TYPE* map, HM_INT_TYPE key) {
1327 0 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return false;
Branch: 27 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 4 0 4
if (!map || HM_IS_RESERVED_KEY(key)) return false; 4 0 4
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 4 4
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
1328 0 size_t index = HM_FN(find_node)(map, key);
1329 0 ▶ if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false;
Branch: 18 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 4 0 4
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 4 4
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == HM_EMPTY_KEY) return false; 0 0 0
1330 0 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 27 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 4 0 4
HM_TTL_CHECK_EXPIRED(map, index, true); 4 0 4
HM_TTL_CHECK_EXPIRED(map, index, true); 1 3 4
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1331 0 ▶ if (map->expires_at) map->expires_at[index] = 0;
Branch: 9 branches
BranchTrueFalseTotal
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
if (map->expires_at) map->expires_at[index] = 0; 3 0 3
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
1332 0 return true;
1333 }
1334 #else
1335 0 static bool HM_FN(persist)(HM_MAP_TYPE* map,
1336 const char* key, uint32_t key_len, uint32_t key_hash) {
1337 0 ▶ if (!map || !key) return false;
Branch: 10 branches
BranchTrueFalseTotal
if (!map || !key) return false; 0 0 0
if (!map || !key) return false; 0 0 0
if (!map || !key) return false; 0 0 0
if (!map || !key) return false; 0 0 0
if (!map || !key) return false; 3 0 3
if (!map || !key) return false; 0 3 3
if (!map || !key) return false; 0 0 0
if (!map || !key) return false; 0 0 0
if (!map || !key) return false; 0 0 0
if (!map || !key) return false; 0 0 0
1338 0 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1339 0 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 10 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 3 0 3
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 3 3
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
1340 0 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 15 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 3 0 3
HM_TTL_CHECK_EXPIRED(map, index, true); 3 0 3
HM_TTL_CHECK_EXPIRED(map, index, true); 0 3 3
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1341 0 ▶ if (map->expires_at) map->expires_at[index] = 0;
Branch: 5 branches
BranchTrueFalseTotal
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
if (map->expires_at) map->expires_at[index] = 0; 3 0 3
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
if (map->expires_at) map->expires_at[index] = 0; 0 0 0
1342 0 return true;
1343 }
1344 #endif
1345  
1346 /* ---- swap: replace value, return old value ---- */
1347  
1348 #ifdef HM_KEY_IS_INT
1349  
1350 #ifdef HM_VALUE_IS_STR
1351 0 static bool HM_FN(swap)(HM_MAP_TYPE* map, HM_INT_TYPE key,
1352 const char* new_val, uint32_t new_len, bool new_utf8,
1353 const char** out_old, uint32_t* out_old_len, bool* out_old_utf8) {
1354 0 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
1355 0 size_t index = HM_FN(find_node)(map, key);
1356 0 ▶ if (index >= map->capacity || map->nodes[index].key != key) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
1357 0 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1358 0 *out_old = map->nodes[index].value;
1359 0 *out_old_len = HM_UNPACK_LEN(map->nodes[index].val_len);
1360 0 *out_old_utf8 = HM_UNPACK_UTF8(map->nodes[index].val_len);
1361 0 ▶ if (new_val && new_len > 0) {
Branch: 6 branches
BranchTrueFalseTotal
if (new_val && new_len > 0) { 0 0 0
if (new_val && new_len > 0) { 0 0 0
if (new_val && new_len > 0) { 0 0 0
if (new_val && new_len > 0) { 0 0 0
if (new_val && new_len > 0) { 0 0 0
if (new_val && new_len > 0) { 0 0 0
1362 0 char* buf = (char*)malloc(new_len + 1);
1363 0 ▶ if (!buf) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (!buf) return false; 0 0 0
if (!buf) return false; 0 0 0
if (!buf) return false; 0 0 0
1364 0 memcpy(buf, new_val, new_len);
1365 0 buf[new_len] = '\0';
1366 0 map->nodes[index].value = buf;
1367 0 ▶ } else if (new_val) {
Branch: 3 branches
BranchTrueFalseTotal
} else if (new_val) { 0 0 0
} else if (new_val) { 0 0 0
} else if (new_val) { 0 0 0
1368 0 char* buf = (char*)malloc(1);
1369 0 ▶ if (!buf) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (!buf) return false; 0 0 0
if (!buf) return false; 0 0 0
if (!buf) return false; 0 0 0
1370 0 buf[0] = '\0';
1371 0 map->nodes[index].value = buf;
1372 } else {
1373 0 map->nodes[index].value = NULL;
1374 }
1375 0 ▶ map->nodes[index].val_len = HM_PACK_LEN(new_len, new_utf8);
Branch: 3 branches
BranchTrueFalseTotal
map->nodes[index].val_len = HM_PACK_LEN(new_len, new_utf8); 0 0 0
map->nodes[index].val_len = HM_PACK_LEN(new_len, new_utf8); 0 0 0
map->nodes[index].val_len = HM_PACK_LEN(new_len, new_utf8); 0 0 0
1376 0 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
1377 0 return true;
1378 }
1379 #elif defined(HM_VALUE_IS_SV)
1380 14 static bool HM_FN(swap)(HM_MAP_TYPE* map, HM_INT_TYPE key,
1381 void* new_val, void** out_old) {
1382 14 ▶ if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 6 0 6
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 6 0 6
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 6 0 6
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 6 6
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 4 0 4
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 4 0 4
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 4 0 4
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 4 4
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 4 0 4
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 4 0 4
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 4 0 4
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 4 4
1383 14 size_t index = HM_FN(find_node)(map, key);
1384 14 ▶ if (index >= map->capacity || map->nodes[index].key != key) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key != key) return false; 6 0 6
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 5 6
if (index >= map->capacity || map->nodes[index].key != key) return false; 4 0 4
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 4 4
if (index >= map->capacity || map->nodes[index].key != key) return false; 4 0 4
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 4 4
1385 13 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 4 1 5
HM_TTL_CHECK_EXPIRED(map, index, true); 0 4 4
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 4 0 4
HM_TTL_CHECK_EXPIRED(map, index, true); 0 4 4
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 4 0 4
HM_TTL_CHECK_EXPIRED(map, index, true); 0 4 4
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1386 13 *out_old = map->nodes[index].value;
1387 13 map->nodes[index].value = new_val;
1388 13 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 5 5
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 4 4
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 4 4
1389 13 return true;
1390 }
1391 #else
1392 0 static bool HM_FN(swap)(HM_MAP_TYPE* map, HM_INT_TYPE key,
1393 HM_INT_TYPE new_val, HM_INT_TYPE* out_old) {
1394 0 ▶ if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 5 0 5
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 5 0 5
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 5 0 5
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 5 5
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || !out_old || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
1395 0 size_t index = HM_FN(find_node)(map, key);
1396 0 ▶ if (index >= map->capacity || map->nodes[index].key != key) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key != key) return false; 5 0 5
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 4 5
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
1397 0 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 4 4
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1398 0 *out_old = map->nodes[index].value;
1399 0 map->nodes[index].value = new_val;
1400 0 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 1 3 4
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
1401 0 return true;
1402 }
1403 #endif
1404  
1405 #else /* string keys */
1406  
1407 #ifdef HM_VALUE_IS_STR
1408 6 static bool HM_FN(swap)(HM_MAP_TYPE* map,
1409 const char* key, uint32_t key_len, uint32_t key_hash,
1410 const char* new_val, uint32_t new_len, bool new_utf8,
1411 const char** out_old, uint32_t* out_old_len, bool* out_old_utf8) {
1412 6 ▶ if (!map || !key) return false;
Branch: 2 branches
BranchTrueFalseTotal
if (!map || !key) return false; 6 0 6
if (!map || !key) return false; 0 6 6
1413 6 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1414 6 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 2 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 6 0 6
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 5 6
1415 5 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 3 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 1 4 5
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1416 5 *out_old = map->nodes[index].value;
1417 5 *out_old_len = HM_UNPACK_LEN(map->nodes[index].val_len);
1418 5 *out_old_utf8 = HM_UNPACK_UTF8(map->nodes[index].val_len);
1419 5 ▶ if (new_val && new_len > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (new_val && new_len > 0) { 5 0 5
if (new_val && new_len > 0) { 5 0 5
1420 5 char* buf = (char*)malloc(new_len + 1);
1421 5 ▶ if (!buf) return false;
Branch: 1 branch
BranchTrueFalseTotal
if (!buf) return false; 0 5 5
1422 5 memcpy(buf, new_val, new_len);
1423 5 buf[new_len] = '\0';
1424 5 map->nodes[index].value = buf;
1425 0 ▶ } else if (new_val) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (new_val) { 0 0 0
1426 0 char* buf = (char*)malloc(1);
1427 0 ▶ if (!buf) return false;
Branch: 1 branch
BranchTrueFalseTotal
if (!buf) return false; 0 0 0
1428 0 buf[0] = '\0';
1429 0 map->nodes[index].value = buf;
1430 } else {
1431 0 map->nodes[index].value = NULL;
1432 }
1433 5 ▶ map->nodes[index].val_len = HM_PACK_LEN(new_len, new_utf8);
Branch: 1 branch
BranchTrueFalseTotal
map->nodes[index].val_len = HM_PACK_LEN(new_len, new_utf8); 0 5 5
1434 5 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 1 branch
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 5 5
1435 5 return true;
1436 }
1437 #elif defined(HM_VALUE_IS_SV)
1438 6 static bool HM_FN(swap)(HM_MAP_TYPE* map,
1439 const char* key, uint32_t key_len, uint32_t key_hash,
1440 void* new_val, void** out_old) {
1441 6 ▶ if (!map || !key || !out_old) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (!map || !key || !out_old) return false; 6 0 6
if (!map || !key || !out_old) return false; 6 0 6
if (!map || !key || !out_old) return false; 0 6 6
1442 6 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1443 6 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 2 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 6 0 6
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 6 6
1444 6 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 3 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 4 2 6
HM_TTL_CHECK_EXPIRED(map, index, true); 0 4 4
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1445 6 *out_old = map->nodes[index].value;
1446 6 map->nodes[index].value = new_val;
1447 6 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 1 branch
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 6 6
1448 6 return true;
1449 }
1450 #else
1451 0 static bool HM_FN(swap)(HM_MAP_TYPE* map,
1452 const char* key, uint32_t key_len, uint32_t key_hash,
1453 HM_INT_TYPE new_val, HM_INT_TYPE* out_old) {
1454 0 ▶ if (!map || !key || !out_old) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (!map || !key || !out_old) return false; 0 0 0
if (!map || !key || !out_old) return false; 0 0 0
if (!map || !key || !out_old) return false; 0 0 0
if (!map || !key || !out_old) return false; 0 0 0
if (!map || !key || !out_old) return false; 0 0 0
if (!map || !key || !out_old) return false; 0 0 0
if (!map || !key || !out_old) return false; 0 0 0
if (!map || !key || !out_old) return false; 0 0 0
if (!map || !key || !out_old) return false; 0 0 0
1455 0 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1456 0 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
1457 0 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1458 0 *out_old = map->nodes[index].value;
1459 0 map->nodes[index].value = new_val;
1460 0 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
1461 0 return true;
1462 }
1463 #endif
1464  
1465 #endif /* HM_KEY_IS_INT */
1466  
1467 /* ---- cas: compare-and-swap (int values only) ---- */
1468  
1469 #if !defined(HM_VALUE_IS_STR) && !defined(HM_VALUE_IS_SV)
1470  
1471 #ifdef HM_KEY_IS_INT
1472 0 static bool HM_FN(cas)(HM_MAP_TYPE* map, HM_INT_TYPE key,
1473 HM_INT_TYPE expected, HM_INT_TYPE new_val) {
1474 0 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return false; 5 0 5
if (!map || HM_IS_RESERVED_KEY(key)) return false; 5 0 5
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 5 5
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return false; 0 0 0
1475 0 size_t index = HM_FN(find_node)(map, key);
1476 0 ▶ if (index >= map->capacity || map->nodes[index].key != key) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key != key) return false; 5 0 5
if (index >= map->capacity || map->nodes[index].key != key) return false; 1 4 5
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key != key) return false; 0 0 0
1477 0 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 4 4
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1478 0 ▶ if (map->nodes[index].value != expected) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (map->nodes[index].value != expected) return false; 2 2 4
if (map->nodes[index].value != expected) return false; 0 0 0
if (map->nodes[index].value != expected) return false; 0 0 0
1479 0 map->nodes[index].value = new_val;
1480 0 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 1 1 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
1481 0 return true;
1482 }
1483 #else
1484 0 static bool HM_FN(cas)(HM_MAP_TYPE* map,
1485 const char* key, uint32_t key_len, uint32_t key_hash,
1486 HM_INT_TYPE expected, HM_INT_TYPE new_val) {
1487 0 ▶ if (!map || !key) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (!map || !key) return false; 0 0 0
if (!map || !key) return false; 0 0 0
if (!map || !key) return false; 1 0 1
if (!map || !key) return false; 0 1 1
if (!map || !key) return false; 0 0 0
if (!map || !key) return false; 0 0 0
1488 0 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1489 0 ▶ if (index >= map->capacity || map->nodes[index].key == NULL) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 1 0 1
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 1 1
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
if (index >= map->capacity || map->nodes[index].key == NULL) return false; 0 0 0
1490 0 ▶ HM_TTL_CHECK_EXPIRED(map, index, true);
Branch: 9 branches
BranchTrueFalseTotal
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 1 1
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
HM_TTL_CHECK_EXPIRED(map, index, true); 0 0 0
1491 0 ▶ if (map->nodes[index].value != expected) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (map->nodes[index].value != expected) return false; 0 0 0
if (map->nodes[index].value != expected) return false; 0 1 1
if (map->nodes[index].value != expected) return false; 0 0 0
1492 0 map->nodes[index].value = new_val;
1493 0 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
1494 0 return true;
1495 }
1496 #endif
1497  
1498 #endif /* int values only */
1499  
1500 /* ---- Counter operations (int values only) ---- */
1501  
1502 #ifdef HM_HAS_COUNTERS
1503  
1504 #ifdef HM_KEY_IS_INT
1505  
1506 21 static inline size_t HM_FN(find_or_allocate)(HM_MAP_TYPE* map, HM_INT_TYPE key) {
1507 21 size_t index = hm_hash_int64((int64_t)key) & map->mask;
1508 21 const size_t original_index = index;
1509 21 HM_NODE_TYPE* nodes = map->nodes;
1510 21 size_t first_tombstone = map->capacity;
1511  
1512 do {
1513 26 HM_INT_TYPE k = nodes[index].key;
1514 26 ▶ if (k == key) return index;
Branch: 3 branches
BranchTrueFalseTotal
if (k == key) return index; 0 12 12
if (k == key) return index; 0 6 6
if (k == key) return index; 0 8 8
1515 26 ▶ if (k == HM_EMPTY_KEY) {
Branch: 3 branches
BranchTrueFalseTotal
if (k == HM_EMPTY_KEY) { 10 2 12
if (k == HM_EMPTY_KEY) { 5 1 6
if (k == HM_EMPTY_KEY) { 6 2 8
1516 21 ▶ size_t target = (first_tombstone < map->capacity) ? first_tombstone : index;
Branch: 3 branches
BranchTrueFalseTotal
size_t target = (first_tombstone < map->capacity) ? first_tombstone : index; 2 8 10
size_t target = (first_tombstone < map->capacity) ? first_tombstone : index; 1 4 5
size_t target = (first_tombstone < map->capacity) ? first_tombstone : index; 2 4 6
1517 21 ▶ if (HM_SLOT_IS_TOMBSTONE(&nodes[target])) map->tombstones--;
Branch: 3 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_TOMBSTONE(&nodes[target])) map->tombstones--; 2 8 10
if (HM_SLOT_IS_TOMBSTONE(&nodes[target])) map->tombstones--; 1 4 5
if (HM_SLOT_IS_TOMBSTONE(&nodes[target])) map->tombstones--; 2 4 6
1518 21 nodes[target].key = key;
1519 21 nodes[target].value = 0;
1520 21 map->size++;
1521 21 return target;
1522 }
1523 5 ▶ if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) {
Branch: 6 branches
BranchTrueFalseTotal
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 2 0 2
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 2 0 2
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 1 0 1
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 1 0 1
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 2 0 2
if (k == HM_TOMBSTONE_KEY && first_tombstone >= map->capacity) { 2 0 2
1524 5 first_tombstone = index;
1525 }
1526 5 index = (index + 1) & map->mask;
1527 5 ▶ } while (index != original_index);
Branch: 3 branches
BranchTrueFalseTotal
} while (index != original_index); 2 0 2
} while (index != original_index); 1 0 1
} while (index != original_index); 2 0 2
1528  
1529 0 ▶ if (first_tombstone < map->capacity) {
Branch: 3 branches
BranchTrueFalseTotal
if (first_tombstone < map->capacity) { 0 0 0
if (first_tombstone < map->capacity) { 0 0 0
if (first_tombstone < map->capacity) { 0 0 0
1530 0 map->tombstones--;
1531 0 nodes[first_tombstone].key = key;
1532 0 nodes[first_tombstone].value = 0;
1533 0 map->size++;
1534 0 return first_tombstone;
1535 }
1536 0 return map->capacity;
1537 }
1538  
1539 15035 static bool HM_FN(increment)(HM_MAP_TYPE* map, HM_INT_TYPE key, HM_INT_TYPE* out_value) {
1540 15035 ▶ if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 15014 0 15014
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 15014 0 15014
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 15013 1 15014
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 15013 15013
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 9 0 9
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 9 0 9
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 8 1 9
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 8 8
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 12 0 12
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 12 0 12
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 11 1 12
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 11 11
1541  
1542 15032 size_t index = HM_FN(find_node)(map, key);
1543 15032 ▶ if (index < map->capacity && map->nodes[index].key == key) {
Branch: 6 branches
BranchTrueFalseTotal
if (index < map->capacity && map->nodes[index].key == key) { 15013 0 15013
if (index < map->capacity && map->nodes[index].key == key) { 4 15009 15013
if (index < map->capacity && map->nodes[index].key == key) { 8 0 8
if (index < map->capacity && map->nodes[index].key == key) { 2 6 8
if (index < map->capacity && map->nodes[index].key == key) { 11 0 11
if (index < map->capacity && map->nodes[index].key == key) { 3 8 11
1544 15023 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 3 15006 15009
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 3 0 3
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 6 6
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 8 8
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
1545 0 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 3 branches
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 1 2 3
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
1546 0 HM_FN(expire_at)(map, index, true);
1547 0 goto new_key;
1548 }
1549 15022 ▶ if (map->nodes[index].value == HM_INT_MAX) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (map->nodes[index].value == HM_INT_MAX) return false; 2 15006 15008
if (map->nodes[index].value == HM_INT_MAX) return false; 1 5 6
if (map->nodes[index].value == HM_INT_MAX) return false; 2 6 8
1550 15017 *out_value = ++map->nodes[index].value;
1551 15017 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 1 15005 15006
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 5 5
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 6 6
1552 15017 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 2 15004 15006
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 1 1 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 5 5
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 6 6
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
1553 15017 return true;
1554 }
1555  
1556 9 new_key:
1557 10 ▶ if (map->max_size > 0 && map->size >= map->max_size)
Branch: 6 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) 1 4 5
if (map->max_size > 0 && map->size >= map->max_size) 1 0 1
if (map->max_size > 0 && map->size >= map->max_size) 0 2 2
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 3 3
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
1558 0 HM_FN(lru_evict_one)(map);
1559  
1560 10 ▶ HM_ENSURE_CAPACITY(map, false);
Branch: 18 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, false); 0 5 5
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 2 2
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 3 3
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
1561  
1562 10 index = HM_FN(find_or_allocate)(map, key);
1563 10 ▶ if (index >= map->capacity) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return false; 0 5 5
if (index >= map->capacity) return false; 0 2 2
if (index >= map->capacity) return false; 0 3 3
1564 10 *out_value = ++map->nodes[index].value;
1565 10 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 1 4 5
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 3 3
1566 10 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 1 4 5
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 1 0 1
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 2 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 1 2 3
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 1 0 1
1567 10 return true;
1568 }
1569  
1570 25 static bool HM_FN(increment_by)(HM_MAP_TYPE* map, HM_INT_TYPE key, HM_INT_TYPE delta, HM_INT_TYPE* out_value) {
1571 25 ▶ if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 8 0 8
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 8 0 8
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 8 0 8
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 8 8
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 9 0 9
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 9 0 9
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 9 0 9
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 9 9
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 8 0 8
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 8 0 8
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 8 0 8
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 8 8
1572  
1573 25 size_t index = HM_FN(find_node)(map, key);
1574 25 ▶ if (index < map->capacity && map->nodes[index].key == key) {
Branch: 6 branches
BranchTrueFalseTotal
if (index < map->capacity && map->nodes[index].key == key) { 8 0 8
if (index < map->capacity && map->nodes[index].key == key) { 3 5 8
if (index < map->capacity && map->nodes[index].key == key) { 9 0 9
if (index < map->capacity && map->nodes[index].key == key) { 2 7 9
if (index < map->capacity && map->nodes[index].key == key) { 8 0 8
if (index < map->capacity && map->nodes[index].key == key) { 2 6 8
1575 18 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 5 5
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 7 7
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 6 6
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
1576 0 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 3 branches
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
1577 0 HM_FN(expire_at)(map, index, true);
1578 0 goto new_key;
1579 }
1580 18 HM_INT_TYPE val = map->nodes[index].value;
1581 18 ▶ if (delta > 0 && val > HM_INT_MAX - delta) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (delta > 0 && val > HM_INT_MAX - delta) return false; 2 3 5
if (delta > 0 && val > HM_INT_MAX - delta) return false; 1 1 2
if (delta > 0 && val > HM_INT_MAX - delta) return false; 4 3 7
if (delta > 0 && val > HM_INT_MAX - delta) return false; 1 3 4
if (delta > 0 && val > HM_INT_MAX - delta) return false; 3 3 6
if (delta > 0 && val > HM_INT_MAX - delta) return false; 1 2 3
1582 15 ▶ if (delta < 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (delta < 0) { 2 2 4
if (delta < 0) { 2 4 6
if (delta < 0) { 2 3 5
1583 6 ▶ if (delta == HM_INT_MIN) { if (val < 0) return false; }
Branch: 6 branches
BranchTrueFalseTotal
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 2 2
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 0 0
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 2 2
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 0 0
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 2 2
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 0 0
1584 6 ▶ else { if (val < HM_INT_MIN - delta) return false; }
Branch: 3 branches
BranchTrueFalseTotal
else { if (val < HM_INT_MIN - delta) return false; } 1 1 2
else { if (val < HM_INT_MIN - delta) return false; } 1 1 2
else { if (val < HM_INT_MIN - delta) return false; } 1 1 2
1585 }
1586 12 map->nodes[index].value += delta;
1587 12 *out_value = map->nodes[index].value;
1588 12 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 3 3
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 5 5
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 4 4
1589 12 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 3 3
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 5 5
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 4 4
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
1590 12 return true;
1591 }
1592  
1593 7 new_key:
1594 7 ▶ if (map->max_size > 0 && map->size >= map->max_size)
Branch: 6 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) 0 3 3
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 2 2
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 2 2
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
1595 0 HM_FN(lru_evict_one)(map);
1596  
1597 7 ▶ HM_ENSURE_CAPACITY(map, false);
Branch: 18 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, false); 0 3 3
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 2 2
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 2 2
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
1598  
1599 7 index = HM_FN(find_or_allocate)(map, key);
1600 7 ▶ if (index >= map->capacity) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return false; 0 3 3
if (index >= map->capacity) return false; 0 2 2
if (index >= map->capacity) return false; 0 2 2
1601 7 map->nodes[index].value = delta;
1602 7 *out_value = delta;
1603 7 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 3 3
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 2 2
1604 7 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 3 3
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 2 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 2 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
1605 7 return true;
1606 }
1607  
1608 5021 static bool HM_FN(decrement)(HM_MAP_TYPE* map, HM_INT_TYPE key, HM_INT_TYPE* out_value) {
1609 5021 ▶ if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 5006 0 5006
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 5006 0 5006
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 5005 1 5006
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 5005 5005
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 9 0 9
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 9 0 9
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 8 1 9
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 8 8
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 6 0 6
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 6 0 6
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 5 1 6
if (!map || !out_value || HM_IS_RESERVED_KEY(key)) return false; 0 5 5
1610  
1611 5018 size_t index = HM_FN(find_node)(map, key);
1612 5018 ▶ if (index < map->capacity && map->nodes[index].key == key) {
Branch: 6 branches
BranchTrueFalseTotal
if (index < map->capacity && map->nodes[index].key == key) { 5005 0 5005
if (index < map->capacity && map->nodes[index].key == key) { 2 5003 5005
if (index < map->capacity && map->nodes[index].key == key) { 8 0 8
if (index < map->capacity && map->nodes[index].key == key) { 1 7 8
if (index < map->capacity && map->nodes[index].key == key) { 5 0 5
if (index < map->capacity && map->nodes[index].key == key) { 1 4 5
1613 5014 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 5003 5003
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 7 7
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 4 4
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
1614 0 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 3 branches
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
1615 0 HM_FN(expire_at)(map, index, true);
1616 0 goto new_key;
1617 }
1618 5014 ▶ if (map->nodes[index].value == HM_INT_MIN) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (map->nodes[index].value == HM_INT_MIN) return false; 1 5002 5003
if (map->nodes[index].value == HM_INT_MIN) return false; 2 5 7
if (map->nodes[index].value == HM_INT_MIN) return false; 1 3 4
1619 5010 *out_value = --map->nodes[index].value;
1620 5010 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 5002 5002
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 5 5
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 3 3
1621 5010 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 5002 5002
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 5 5
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 3 3
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
1622 5010 return true;
1623 }
1624  
1625 4 new_key:
1626 4 ▶ if (map->max_size > 0 && map->size >= map->max_size)
Branch: 6 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) 0 2 2
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 1 1
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 1 1
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
1627 0 HM_FN(lru_evict_one)(map);
1628  
1629 4 ▶ HM_ENSURE_CAPACITY(map, false);
Branch: 18 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, false); 0 2 2
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 1 1
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 1 1
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
1630  
1631 4 index = HM_FN(find_or_allocate)(map, key);
1632 4 ▶ if (index >= map->capacity) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return false; 0 2 2
if (index >= map->capacity) return false; 0 1 1
if (index >= map->capacity) return false; 0 1 1
1633 4 *out_value = --map->nodes[index].value;
1634 4 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 1 1
1635 4 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 2 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 1 1
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 1 1
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
1636 4 return true;
1637 }
1638  
1639 #else /* string keys + counters */
1640  
1641 22 static inline size_t HM_FN(find_or_allocate)(HM_MAP_TYPE* map,
1642 const char* key, uint32_t key_len,
1643 uint32_t key_hash, bool key_utf8) {
1644 22 size_t index = (size_t)key_hash & map->mask;
1645 22 const size_t original_index = index;
1646 22 HM_NODE_TYPE* nodes = map->nodes;
1647 22 size_t first_tombstone = map->capacity;
1648  
1649 do {
1650 29 ▶ if (nodes[index].key == NULL) {
Branch: 3 branches
BranchTrueFalseTotal
if (nodes[index].key == NULL) { 5 2 7
if (nodes[index].key == NULL) { 11 2 13
if (nodes[index].key == NULL) { 6 3 9
1651 22 ▶ size_t target = (first_tombstone < map->capacity) ? first_tombstone : index;
Branch: 3 branches
BranchTrueFalseTotal
size_t target = (first_tombstone < map->capacity) ? first_tombstone : index; 1 4 5
size_t target = (first_tombstone < map->capacity) ? first_tombstone : index; 2 9 11
size_t target = (first_tombstone < map->capacity) ? first_tombstone : index; 2 4 6
1652 22 char* new_key = (char*)malloc(key_len + 1);
1653 22 ▶ if (!new_key) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (!new_key) return map->capacity; 0 5 5
if (!new_key) return map->capacity; 0 11 11
if (!new_key) return map->capacity; 0 6 6
1654 22 memcpy(new_key, key, key_len);
1655 22 new_key[key_len] = '\0';
1656 22 ▶ if (HM_SLOT_IS_TOMBSTONE(&nodes[target])) map->tombstones--;
Branch: 3 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_TOMBSTONE(&nodes[target])) map->tombstones--; 1 4 5
if (HM_SLOT_IS_TOMBSTONE(&nodes[target])) map->tombstones--; 2 9 11
if (HM_SLOT_IS_TOMBSTONE(&nodes[target])) map->tombstones--; 2 4 6
1657 22 nodes[target].key = new_key;
1658 22 ▶ nodes[target].key_len = HM_PACK_LEN(key_len, key_utf8);
Branch: 3 branches
BranchTrueFalseTotal
nodes[target].key_len = HM_PACK_LEN(key_len, key_utf8); 0 5 5
nodes[target].key_len = HM_PACK_LEN(key_len, key_utf8); 0 11 11
nodes[target].key_len = HM_PACK_LEN(key_len, key_utf8); 0 6 6
1659 22 nodes[target].key_hash = key_hash;
1660 22 nodes[target].value = 0;
1661 22 map->size++;
1662 22 return target;
1663 }
1664 7 ▶ if (nodes[index].key == HM_STR_TOMBSTONE) {
Branch: 3 branches
BranchTrueFalseTotal
if (nodes[index].key == HM_STR_TOMBSTONE) { 1 1 2
if (nodes[index].key == HM_STR_TOMBSTONE) { 2 0 2
if (nodes[index].key == HM_STR_TOMBSTONE) { 2 1 3
1665 5 ▶ if (first_tombstone >= map->capacity) first_tombstone = index;
Branch: 3 branches
BranchTrueFalseTotal
if (first_tombstone >= map->capacity) first_tombstone = index; 1 0 1
if (first_tombstone >= map->capacity) first_tombstone = index; 2 0 2
if (first_tombstone >= map->capacity) first_tombstone = index; 2 0 2
1666 0 ▶ } else if (nodes[index].key_hash == key_hash &&
Branch: 3 branches
BranchTrueFalseTotal
} else if (nodes[index].key_hash == key_hash && 0 1 1
} else if (nodes[index].key_hash == key_hash && 0 0 0
} else if (nodes[index].key_hash == key_hash && 0 1 1
1667 0 ▶ HM_UNPACK_LEN(nodes[index].key_len) == key_len &&
Branch: 3 branches
BranchTrueFalseTotal
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 0 0 0
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 0 0 0
HM_UNPACK_LEN(nodes[index].key_len) == key_len && 0 0 0
1668 0 ▶ memcmp(nodes[index].key, key, key_len) == 0) {
Branch: 3 branches
BranchTrueFalseTotal
memcmp(nodes[index].key, key, key_len) == 0) { 0 0 0
memcmp(nodes[index].key, key, key_len) == 0) { 0 0 0
memcmp(nodes[index].key, key, key_len) == 0) { 0 0 0
1669 0 return index;
1670 }
1671 7 index = (index + 1) & map->mask;
1672 7 ▶ } while (index != original_index);
Branch: 3 branches
BranchTrueFalseTotal
} while (index != original_index); 2 0 2
} while (index != original_index); 2 0 2
} while (index != original_index); 3 0 3
1673  
1674 0 ▶ if (first_tombstone < map->capacity) {
Branch: 3 branches
BranchTrueFalseTotal
if (first_tombstone < map->capacity) { 0 0 0
if (first_tombstone < map->capacity) { 0 0 0
if (first_tombstone < map->capacity) { 0 0 0
1675 0 char* new_key = (char*)malloc(key_len + 1);
1676 0 ▶ if (!new_key) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (!new_key) return map->capacity; 0 0 0
if (!new_key) return map->capacity; 0 0 0
if (!new_key) return map->capacity; 0 0 0
1677 0 memcpy(new_key, key, key_len);
1678 0 new_key[key_len] = '\0';
1679 0 map->tombstones--;
1680 0 nodes[first_tombstone].key = new_key;
1681 0 ▶ nodes[first_tombstone].key_len = HM_PACK_LEN(key_len, key_utf8);
Branch: 3 branches
BranchTrueFalseTotal
nodes[first_tombstone].key_len = HM_PACK_LEN(key_len, key_utf8); 0 0 0
nodes[first_tombstone].key_len = HM_PACK_LEN(key_len, key_utf8); 0 0 0
nodes[first_tombstone].key_len = HM_PACK_LEN(key_len, key_utf8); 0 0 0
1682 0 nodes[first_tombstone].key_hash = key_hash;
1683 0 nodes[first_tombstone].value = 0;
1684 0 map->size++;
1685 0 return first_tombstone;
1686 }
1687 0 return map->capacity;
1688 }
1689  
1690 15041 static bool HM_FN(increment)(HM_MAP_TYPE* map,
1691 const char* key, uint32_t key_len, uint32_t key_hash, bool key_utf8,
1692 HM_INT_TYPE* out_value) {
1693 15041 ▶ if (!map || !key || !out_value) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (!map || !key || !out_value) return false; 13 0 13
if (!map || !key || !out_value) return false; 13 0 13
if (!map || !key || !out_value) return false; 0 13 13
if (!map || !key || !out_value) return false; 15017 0 15017
if (!map || !key || !out_value) return false; 15017 0 15017
if (!map || !key || !out_value) return false; 0 15017 15017
if (!map || !key || !out_value) return false; 11 0 11
if (!map || !key || !out_value) return false; 11 0 11
if (!map || !key || !out_value) return false; 0 11 11
1694  
1695 15041 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1696 15041 ▶ if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) {
Branch: 9 branches
BranchTrueFalseTotal
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 13 0 13
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 2 11 13
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 0 11 11
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 15017 0 15017
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 7 15010 15017
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 0 15010 15010
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 11 0 11
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 4 7 11
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 0 7 7
1697 15028 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 11 11
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 15010 15010
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 7 7
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
1698 0 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 3 branches
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
1699 0 HM_FN(expire_at)(map, index, true);
1700 0 goto new_key;
1701 }
1702 15028 ▶ if (map->nodes[index].value == HM_INT_MAX) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (map->nodes[index].value == HM_INT_MAX) return false; 1 10 11
if (map->nodes[index].value == HM_INT_MAX) return false; 1 15009 15010
if (map->nodes[index].value == HM_INT_MAX) return false; 1 6 7
1703 15025 *out_value = ++map->nodes[index].value;
1704 15025 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 10 10
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 1 15008 15009
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 1 5 6
1705 15025 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 10 10
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 15009 15009
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 6 6
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
1706 15025 return true;
1707 }
1708  
1709 13 new_key:
1710 13 ▶ if (map->max_size > 0 && map->size >= map->max_size)
Branch: 6 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) 0 2 2
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 7 7
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 4 4
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
1711 0 HM_FN(lru_evict_one)(map);
1712  
1713 13 ▶ HM_ENSURE_CAPACITY(map, false);
Branch: 18 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, false); 0 2 2
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 7 7
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 4 4
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
1714  
1715 13 index = HM_FN(find_or_allocate)(map, key, key_len, key_hash, key_utf8);
1716 13 ▶ if (index >= map->capacity) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return false; 0 2 2
if (index >= map->capacity) return false; 0 7 7
if (index >= map->capacity) return false; 0 4 4
1717 13 *out_value = ++map->nodes[index].value;
1718 13 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 7 7
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 4 4
1719 13 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 2 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 1 6 7
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 1 0 1
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 1 3 4
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 1 0 1
1720 13 return true;
1721 }
1722  
1723 18 static bool HM_FN(increment_by)(HM_MAP_TYPE* map,
1724 const char* key, uint32_t key_len, uint32_t key_hash, bool key_utf8,
1725 HM_INT_TYPE delta, HM_INT_TYPE* out_value) {
1726 18 ▶ if (!map || !key || !out_value) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (!map || !key || !out_value) return false; 6 0 6
if (!map || !key || !out_value) return false; 6 0 6
if (!map || !key || !out_value) return false; 0 6 6
if (!map || !key || !out_value) return false; 6 0 6
if (!map || !key || !out_value) return false; 6 0 6
if (!map || !key || !out_value) return false; 0 6 6
if (!map || !key || !out_value) return false; 6 0 6
if (!map || !key || !out_value) return false; 6 0 6
if (!map || !key || !out_value) return false; 0 6 6
1727  
1728 18 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1729 18 ▶ if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) {
Branch: 9 branches
BranchTrueFalseTotal
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 6 0 6
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 2 4 6
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 0 4 4
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 6 0 6
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 2 4 6
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 0 4 4
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 6 0 6
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 1 5 6
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 0 5 5
1730 13 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 4 4
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 4 4
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 5 5
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
1731 0 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 3 branches
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
1732 0 HM_FN(expire_at)(map, index, true);
1733 0 goto new_key;
1734 }
1735 13 HM_INT_TYPE val = map->nodes[index].value;
1736 13 ▶ if (delta > 0 && val > HM_INT_MAX - delta) return false;
Branch: 6 branches
BranchTrueFalseTotal
if (delta > 0 && val > HM_INT_MAX - delta) return false; 1 3 4
if (delta > 0 && val > HM_INT_MAX - delta) return false; 1 0 1
if (delta > 0 && val > HM_INT_MAX - delta) return false; 1 3 4
if (delta > 0 && val > HM_INT_MAX - delta) return false; 1 0 1
if (delta > 0 && val > HM_INT_MAX - delta) return false; 3 2 5
if (delta > 0 && val > HM_INT_MAX - delta) return false; 1 2 3
1737 10 ▶ if (delta < 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (delta < 0) { 2 1 3
if (delta < 0) { 2 1 3
if (delta < 0) { 2 2 4
1738 6 ▶ if (delta == HM_INT_MIN) { if (val < 0) return false; }
Branch: 6 branches
BranchTrueFalseTotal
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 2 2
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 0 0
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 2 2
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 0 0
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 2 2
if (delta == HM_INT_MIN) { if (val < 0) return false; } 0 0 0
1739 6 ▶ else { if (val < HM_INT_MIN - delta) return false; }
Branch: 3 branches
BranchTrueFalseTotal
else { if (val < HM_INT_MIN - delta) return false; } 1 1 2
else { if (val < HM_INT_MIN - delta) return false; } 1 1 2
else { if (val < HM_INT_MIN - delta) return false; } 1 1 2
1740 }
1741 7 map->nodes[index].value += delta;
1742 7 *out_value = map->nodes[index].value;
1743 7 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 3 3
1744 7 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 2 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 2 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 3 3
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
1745 7 return true;
1746 }
1747  
1748 5 new_key:
1749 5 ▶ if (map->max_size > 0 && map->size >= map->max_size)
Branch: 6 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) 0 2 2
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 2 2
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 1 1
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
1750 0 HM_FN(lru_evict_one)(map);
1751  
1752 5 ▶ HM_ENSURE_CAPACITY(map, false);
Branch: 18 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, false); 0 2 2
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 2 2
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 1 1
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
1753  
1754 5 index = HM_FN(find_or_allocate)(map, key, key_len, key_hash, key_utf8);
1755 5 ▶ if (index >= map->capacity) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return false; 0 2 2
if (index >= map->capacity) return false; 0 2 2
if (index >= map->capacity) return false; 0 1 1
1756 5 map->nodes[index].value = delta;
1757 5 *out_value = delta;
1758 5 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 1 1
1759 5 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 2 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 2 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 1 1
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
1760 5 return true;
1761 }
1762  
1763 5014 static bool HM_FN(decrement)(HM_MAP_TYPE* map,
1764 const char* key, uint32_t key_len, uint32_t key_hash, bool key_utf8,
1765 HM_INT_TYPE* out_value) {
1766 5014 ▶ if (!map || !key || !out_value) return false;
Branch: 9 branches
BranchTrueFalseTotal
if (!map || !key || !out_value) return false; 3 0 3
if (!map || !key || !out_value) return false; 3 0 3
if (!map || !key || !out_value) return false; 0 3 3
if (!map || !key || !out_value) return false; 5006 0 5006
if (!map || !key || !out_value) return false; 5006 0 5006
if (!map || !key || !out_value) return false; 0 5006 5006
if (!map || !key || !out_value) return false; 5 0 5
if (!map || !key || !out_value) return false; 5 0 5
if (!map || !key || !out_value) return false; 0 5 5
1767  
1768 5014 size_t index = HM_FN(find_node)(map, key, key_len, key_hash);
1769 5014 ▶ if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) {
Branch: 9 branches
BranchTrueFalseTotal
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 3 0 3
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 1 2 3
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 0 2 2
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 5006 0 5006
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 2 5004 5006
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 0 5004 5004
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 5 0 5
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 1 4 5
if (index < map->capacity && HM_SLOT_IS_LIVE(&map->nodes[index])) { 0 4 4
1770 5010 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 2 2
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 5004 5004
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 4 4
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
1771 0 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 3 branches
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
1772 0 HM_FN(expire_at)(map, index, true);
1773 0 goto new_key;
1774 }
1775 5010 ▶ if (map->nodes[index].value == HM_INT_MIN) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (map->nodes[index].value == HM_INT_MIN) return false; 1 1 2
if (map->nodes[index].value == HM_INT_MIN) return false; 2 5002 5004
if (map->nodes[index].value == HM_INT_MIN) return false; 1 3 4
1776 5006 *out_value = --map->nodes[index].value;
1777 5006 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 5002 5002
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 3 3
1778 5006 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 1 1
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 5002 5002
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 3 3
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
1779 5006 return true;
1780 }
1781  
1782 4 new_key:
1783 4 ▶ if (map->max_size > 0 && map->size >= map->max_size)
Branch: 6 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) 0 1 1
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 2 2
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) 0 1 1
if (map->max_size > 0 && map->size >= map->max_size) 0 0 0
1784 0 HM_FN(lru_evict_one)(map);
1785  
1786 4 ▶ HM_ENSURE_CAPACITY(map, false);
Branch: 18 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, false); 0 1 1
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 2 2
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 1 1
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
HM_ENSURE_CAPACITY(map, false); 0 0 0
1787  
1788 4 index = HM_FN(find_or_allocate)(map, key, key_len, key_hash, key_utf8);
1789 4 ▶ if (index >= map->capacity) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return false; 0 1 1
if (index >= map->capacity) return false; 0 2 2
if (index >= map->capacity) return false; 0 1 1
1790 4 *out_value = --map->nodes[index].value;
1791 4 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 1 1
1792 4 ▶ if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl);
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 1 1
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 2 2
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 1 1
if (HM_UNLIKELY(map->expires_at && map->default_ttl > 0)) map->expires_at[index] = hm_expiry_at(map->default_ttl); 0 0 0
1793 4 return true;
1794 }
1795  
1796 #endif /* HM_KEY_IS_INT for counters */
1797  
1798 #endif /* HM_HAS_COUNTERS */
1799  
1800 /* ---- get_or_set: single-probe get with insert on miss ---- */
1801  
1802 #ifdef HM_KEY_IS_INT
1803  
1804 #ifdef HM_VALUE_IS_STR
1805 /* get_or_set for int-key, string-value: returns index, sets *was_found */
1806 0 static size_t HM_FN(get_or_set)(HM_MAP_TYPE* map, HM_INT_TYPE key,
1807 const char* def_val, uint32_t def_len, bool def_utf8,
1808 uint32_t entry_ttl, bool* was_found) {
1809 0 *was_found = false;
1810 0 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 9 0 9
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 9 0 9
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 9 9
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 1 0 1
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 1 0 1
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 1 1
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 0 0
1811  
1812 0 ▶ HM_ENSURE_CAPACITY(map, map->capacity);
Branch: 18 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 9 9
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 1 1
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
1813  
1814 bool found;
1815 0 size_t index = HM_FN(find_slot_for_insert)(map, key, &found);
1816 0 ▶ if (index >= map->capacity) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 0 0
if (index >= map->capacity) return map->capacity; 0 9 9
if (index >= map->capacity) return map->capacity; 0 1 1
1817  
1818 0 ▶ if (found) {
Branch: 3 branches
BranchTrueFalseTotal
if (found) { 0 0 0
if (found) { 3 6 9
if (found) { 0 1 1
1819 0 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 3 3
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
1820 0 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 3 branches
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
1821 0 HM_FN(expire_at)(map, index, true);
1822 0 found = false;
1823 /* Re-probe after expiry */
1824 0 index = HM_FN(find_slot_for_insert)(map, key, &found);
1825 0 ▶ if (index >= map->capacity) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 0 0
if (index >= map->capacity) return map->capacity; 0 0 0
if (index >= map->capacity) return map->capacity; 0 0 0
1826 }
1827 }
1828  
1829 0 ▶ if (found) {
Branch: 3 branches
BranchTrueFalseTotal
if (found) { 0 0 0
if (found) { 3 6 9
if (found) { 0 1 1
1830 0 *was_found = true;
1831 0 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 3 3
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 0 0
1832 0 return index;
1833 }
1834  
1835 0 ▶ if (map->max_size > 0 && map->size >= map->max_size) {
Branch: 6 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) { 0 6 6
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) { 0 1 1
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
1836 0 HM_FN(lru_evict_one)(map);
1837 0 index = HM_FN(find_slot_for_insert)(map, key, &found);
1838 0 ▶ if (index >= map->capacity) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 0 0
if (index >= map->capacity) return map->capacity; 0 0 0
if (index >= map->capacity) return map->capacity; 0 0 0
1839 }
1840  
1841 0 ▶ HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity);
Branch: 9 branches
BranchTrueFalseTotal
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 6 6
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 1 1
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
1842  
1843 0 char* new_val = NULL;
1844 0 uint32_t new_val_len = 0;
1845 0 ▶ if (def_val && def_len > 0) {
Branch: 6 branches
BranchTrueFalseTotal
if (def_val && def_len > 0) { 0 0 0
if (def_val && def_len > 0) { 0 0 0
if (def_val && def_len > 0) { 6 0 6
if (def_val && def_len > 0) { 6 0 6
if (def_val && def_len > 0) { 1 0 1
if (def_val && def_len > 0) { 1 0 1
1846 0 new_val = (char*)malloc(def_len + 1);
1847 0 ▶ if (!new_val) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (!new_val) return map->capacity; 0 0 0
if (!new_val) return map->capacity; 0 6 6
if (!new_val) return map->capacity; 0 1 1
1848 0 memcpy(new_val, def_val, def_len);
1849 0 new_val[def_len] = '\0';
1850 0 ▶ new_val_len = HM_PACK_LEN(def_len, def_utf8);
Branch: 3 branches
BranchTrueFalseTotal
new_val_len = HM_PACK_LEN(def_len, def_utf8); 0 0 0
new_val_len = HM_PACK_LEN(def_len, def_utf8); 0 6 6
new_val_len = HM_PACK_LEN(def_len, def_utf8); 0 1 1
1851 0 ▶ } else if (def_val) {
Branch: 3 branches
BranchTrueFalseTotal
} else if (def_val) { 0 0 0
} else if (def_val) { 0 0 0
} else if (def_val) { 0 0 0
1852 0 new_val = (char*)malloc(1);
1853 0 ▶ if (!new_val) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (!new_val) return map->capacity; 0 0 0
if (!new_val) return map->capacity; 0 0 0
if (!new_val) return map->capacity; 0 0 0
1854 0 new_val[0] = '\0';
1855 0 ▶ new_val_len = HM_PACK_LEN(0, def_utf8);
Branch: 3 branches
BranchTrueFalseTotal
new_val_len = HM_PACK_LEN(0, def_utf8); 0 0 0
new_val_len = HM_PACK_LEN(0, def_utf8); 0 0 0
new_val_len = HM_PACK_LEN(0, def_utf8); 0 0 0
1856 }
1857  
1858 0 ▶ if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--;
Branch: 3 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 0 0 0
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 0 6 6
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 0 1 1
1859 0 map->size++;
1860 0 map->nodes[index].key = key;
1861 0 map->nodes[index].value = new_val;
1862 0 map->nodes[index].val_len = new_val_len;
1863  
1864 0 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 0 0
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 6 6
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 1 1
1865 0 ▶ HM_APPLY_ENTRY_TTL(map, index, entry_ttl);
Branch: 9 branches
BranchTrueFalseTotal
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 6 6
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 1 1
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
1866  
1867 0 return index;
1868 }
1869 #elif defined(HM_VALUE_IS_SV)
1870 26 static size_t HM_FN(get_or_set)(HM_MAP_TYPE* map, HM_INT_TYPE key,
1871 void* def_val, uint32_t entry_ttl, bool* was_found) {
1872 26 *was_found = false;
1873 26 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 10 0 10
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 10 0 10
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 10 10
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 8 0 8
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 8 0 8
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 8 8
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 8 0 8
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 8 0 8
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 8 8
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 0 0
1874  
1875 26 ▶ HM_ENSURE_CAPACITY(map, map->capacity);
Branch: 18 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, map->capacity); 0 10 10
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 8 8
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 8 8
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
1876  
1877 bool found;
1878 26 size_t index = HM_FN(find_slot_for_insert)(map, key, &found);
1879 26 ▶ if (index >= map->capacity) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 10 10
if (index >= map->capacity) return map->capacity; 0 8 8
if (index >= map->capacity) return map->capacity; 0 8 8
1880  
1881 26 ▶ if (found) {
Branch: 3 branches
BranchTrueFalseTotal
if (found) { 4 6 10
if (found) { 3 5 8
if (found) { 3 5 8
1882 10 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 3 1 4
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 1 2 3
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 3 0 3
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 1 2 3
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 3 0 3
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 1 2 3
1883 3 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 3 branches
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 1 0 1
(uint32_t)time(NULL) > map->expires_at[index]) { 1 0 1
(uint32_t)time(NULL) > map->expires_at[index]) { 1 0 1
1884 3 HM_FN(expire_at)(map, index, true);
1885 3 found = false;
1886 3 index = HM_FN(find_slot_for_insert)(map, key, &found);
1887 3 ▶ if (index >= map->capacity) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 1 1
if (index >= map->capacity) return map->capacity; 0 1 1
if (index >= map->capacity) return map->capacity; 0 1 1
1888 }
1889 }
1890  
1891 26 ▶ if (found) {
Branch: 3 branches
BranchTrueFalseTotal
if (found) { 3 7 10
if (found) { 2 6 8
if (found) { 2 6 8
1892 7 *was_found = true;
1893 7 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 3 3
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 2 2
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 2 2
1894 7 return index;
1895 }
1896  
1897 19 ▶ if (map->max_size > 0 && map->size >= map->max_size) {
Branch: 6 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) { 0 7 7
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) { 0 6 6
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) { 0 6 6
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
1898 0 HM_FN(lru_evict_one)(map);
1899 0 index = HM_FN(find_slot_for_insert)(map, key, &found);
1900 0 ▶ if (index >= map->capacity) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 0 0
if (index >= map->capacity) return map->capacity; 0 0 0
if (index >= map->capacity) return map->capacity; 0 0 0
1901 }
1902  
1903 19 ▶ HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity);
Branch: 9 branches
BranchTrueFalseTotal
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 7 7
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 6 6
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 6 6
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
1904  
1905 19 ▶ if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--;
Branch: 3 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 1 6 7
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 1 5 6
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 1 5 6
1906 19 map->size++;
1907 19 map->nodes[index].key = key;
1908 19 map->nodes[index].value = def_val;
1909  
1910 19 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 7 7
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 6 6
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 6 6
1911 19 ▶ HM_APPLY_ENTRY_TTL(map, index, entry_ttl);
Branch: 9 branches
BranchTrueFalseTotal
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 6 1 7
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 6 0 6
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 2 4 6
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 6 0 6
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 6 0 6
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 2 4 6
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 6 0 6
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 6 0 6
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 2 4 6
1912  
1913 19 return index;
1914 }
1915 #else
1916 22 static size_t HM_FN(get_or_set)(HM_MAP_TYPE* map, HM_INT_TYPE key,
1917 HM_INT_TYPE def_val, uint32_t entry_ttl, bool* was_found) {
1918 22 *was_found = false;
1919 22 ▶ if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0;
Branch: 12 branches
BranchTrueFalseTotal
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 16 0 16
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 16 0 16
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 16 16
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 0 0
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 3 0 3
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 2 1 3
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 2 2
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 1 0 1
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 3 0 3
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 2 1 3
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 0 2 2
if (!map || HM_IS_RESERVED_KEY(key)) return map ? map->capacity : 0; 1 0 1
1920  
1921 20 ▶ HM_ENSURE_CAPACITY(map, map->capacity);
Branch: 18 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, map->capacity); 0 16 16
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 2 2
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 2 2
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
1922  
1923 bool found;
1924 20 size_t index = HM_FN(find_slot_for_insert)(map, key, &found);
1925 20 ▶ if (index >= map->capacity) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 16 16
if (index >= map->capacity) return map->capacity; 0 2 2
if (index >= map->capacity) return map->capacity; 0 2 2
1926  
1927 20 ▶ if (found) {
Branch: 3 branches
BranchTrueFalseTotal
if (found) { 6 10 16
if (found) { 1 1 2
if (found) { 1 1 2
1928 8 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 6 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 1 5 6
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 1 0 1
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 1 1
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 1 1
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
1929 0 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 3 branches
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 1 0 1
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
1930 0 HM_FN(expire_at)(map, index, true);
1931 0 found = false;
1932 0 index = HM_FN(find_slot_for_insert)(map, key, &found);
1933 0 ▶ if (index >= map->capacity) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 1 1
if (index >= map->capacity) return map->capacity; 0 0 0
if (index >= map->capacity) return map->capacity; 0 0 0
1934 }
1935 }
1936  
1937 20 ▶ if (found) {
Branch: 3 branches
BranchTrueFalseTotal
if (found) { 5 11 16
if (found) { 1 1 2
if (found) { 1 1 2
1938 7 *was_found = true;
1939 7 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 1 4 5
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 1 1
1940 7 return index;
1941 }
1942  
1943 13 ▶ if (map->max_size > 0 && map->size >= map->max_size) {
Branch: 6 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) { 4 7 11
if (map->max_size > 0 && map->size >= map->max_size) { 1 3 4
if (map->max_size > 0 && map->size >= map->max_size) { 0 1 1
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
if (map->max_size > 0 && map->size >= map->max_size) { 0 1 1
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
1944 0 HM_FN(lru_evict_one)(map);
1945 0 index = HM_FN(find_slot_for_insert)(map, key, &found);
1946 0 ▶ if (index >= map->capacity) return map->capacity;
Branch: 3 branches
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 1 1
if (index >= map->capacity) return map->capacity; 0 0 0
if (index >= map->capacity) return map->capacity; 0 0 0
1947 }
1948  
1949 13 ▶ HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity);
Branch: 9 branches
BranchTrueFalseTotal
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 11 11
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 1 1
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 1 1
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
1950  
1951 13 ▶ if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--;
Branch: 3 branches
BranchTrueFalseTotal
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 1 10 11
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 0 1 1
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 0 1 1
1952 13 map->size++;
1953 13 map->nodes[index].key = key;
1954 13 map->nodes[index].value = def_val;
1955  
1956 13 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 3 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 4 7 11
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 1 1
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 1 1
1957 13 ▶ HM_APPLY_ENTRY_TTL(map, index, entry_ttl);
Branch: 9 branches
BranchTrueFalseTotal
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 2 9 11
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 2 0 2
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 1 1 2
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 1 1
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 1 1
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 0 0
1958  
1959 13 return index;
1960 }
1961 #endif
1962  
1963 #else /* string keys */
1964  
1965 #ifdef HM_VALUE_IS_STR
1966 12 static size_t HM_FN(get_or_set)(HM_MAP_TYPE* map,
1967 const char* key, uint32_t key_len, uint32_t key_hash, bool key_utf8,
1968 const char* def_val, uint32_t def_len, bool def_utf8,
1969 uint32_t entry_ttl, bool* was_found) {
1970 12 *was_found = false;
1971 12 ▶ if (!map || !key) return map ? map->capacity : 0;
Branch: 3 branches
BranchTrueFalseTotal
if (!map || !key) return map ? map->capacity : 0; 12 0 12
if (!map || !key) return map ? map->capacity : 0; 0 12 12
if (!map || !key) return map ? map->capacity : 0; 0 0 0
1972  
1973 12 ▶ HM_ENSURE_CAPACITY(map, map->capacity);
Branch: 6 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, map->capacity); 0 12 12
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
1974  
1975 bool found;
1976 12 size_t index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
1977 12 ▶ if (index >= map->capacity) return map->capacity;
Branch: 1 branch
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 12 12
1978  
1979 12 ▶ if (found) {
Branch: 1 branch
BranchTrueFalseTotal
if (found) { 3 9 12
1980 3 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 2 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 3 3
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 0 0 0
1981 0 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 1 branch
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 0 0 0
1982 0 HM_FN(expire_at)(map, index, true);
1983 0 found = false;
1984 0 index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
1985 0 ▶ if (index >= map->capacity) return map->capacity;
Branch: 1 branch
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 0 0
1986 }
1987 }
1988  
1989 12 ▶ if (found) {
Branch: 1 branch
BranchTrueFalseTotal
if (found) { 3 9 12
1990 3 *was_found = true;
1991 3 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 1 branch
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 3 3
1992 3 return index;
1993 }
1994  
1995 9 ▶ if (map->max_size > 0 && map->size >= map->max_size) {
Branch: 2 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) { 0 9 9
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
1996 0 HM_FN(lru_evict_one)(map);
1997 0 index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
1998 0 ▶ if (index >= map->capacity) return map->capacity;
Branch: 1 branch
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 0 0
1999 }
2000  
2001 9 ▶ HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity);
Branch: 3 branches
BranchTrueFalseTotal
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 9 9
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
2002  
2003 9 char* new_key = (char*)malloc(key_len + 1);
2004 9 ▶ if (!new_key) return map->capacity;
Branch: 1 branch
BranchTrueFalseTotal
if (!new_key) return map->capacity; 0 9 9
2005 9 memcpy(new_key, key, key_len);
2006 9 new_key[key_len] = '\0';
2007  
2008 9 char* new_val = NULL;
2009 9 uint32_t new_val_len = 0;
2010 9 ▶ if (def_val && def_len > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (def_val && def_len > 0) { 9 0 9
if (def_val && def_len > 0) { 9 0 9
2011 9 new_val = (char*)malloc(def_len + 1);
2012 9 ▶ if (!new_val) { free(new_key); return map->capacity; }
Branch: 1 branch
BranchTrueFalseTotal
if (!new_val) { free(new_key); return map->capacity; } 0 9 9
2013 9 memcpy(new_val, def_val, def_len);
2014 9 new_val[def_len] = '\0';
2015 9 ▶ new_val_len = HM_PACK_LEN(def_len, def_utf8);
Branch: 1 branch
BranchTrueFalseTotal
new_val_len = HM_PACK_LEN(def_len, def_utf8); 0 9 9
2016 0 ▶ } else if (def_val) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (def_val) { 0 0 0
2017 0 new_val = (char*)malloc(1);
2018 0 ▶ if (!new_val) { free(new_key); return map->capacity; }
Branch: 1 branch
BranchTrueFalseTotal
if (!new_val) { free(new_key); return map->capacity; } 0 0 0
2019 0 new_val[0] = '\0';
2020 0 ▶ new_val_len = HM_PACK_LEN(0, def_utf8);
Branch: 1 branch
BranchTrueFalseTotal
new_val_len = HM_PACK_LEN(0, def_utf8); 0 0 0
2021 }
2022  
2023 9 ▶ if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--;
Branch: 1 branch
BranchTrueFalseTotal
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 0 9 9
2024 9 map->size++;
2025 9 map->nodes[index].key = new_key;
2026 9 ▶ map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8);
Branch: 1 branch
BranchTrueFalseTotal
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 0 9 9
2027 9 map->nodes[index].key_hash = key_hash;
2028 9 map->nodes[index].value = new_val;
2029 9 map->nodes[index].val_len = new_val_len;
2030  
2031 9 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 1 branch
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 9 9
2032 9 ▶ HM_APPLY_ENTRY_TTL(map, index, entry_ttl);
Branch: 3 branches
BranchTrueFalseTotal
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 1 8 9
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 1 0 1
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 0 1 1
2033  
2034 9 return index;
2035 }
2036 #elif defined(HM_VALUE_IS_SV)
2037 10 static size_t HM_FN(get_or_set)(HM_MAP_TYPE* map,
2038 const char* key, uint32_t key_len, uint32_t key_hash, bool key_utf8,
2039 void* def_val, uint32_t entry_ttl, bool* was_found) {
2040 10 *was_found = false;
2041 10 ▶ if (!map || !key) return map ? map->capacity : 0;
Branch: 3 branches
BranchTrueFalseTotal
if (!map || !key) return map ? map->capacity : 0; 10 0 10
if (!map || !key) return map ? map->capacity : 0; 0 10 10
if (!map || !key) return map ? map->capacity : 0; 0 0 0
2042  
2043 10 ▶ HM_ENSURE_CAPACITY(map, map->capacity);
Branch: 6 branches
BranchTrueFalseTotal
HM_ENSURE_CAPACITY(map, map->capacity); 0 10 10
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
HM_ENSURE_CAPACITY(map, map->capacity); 0 0 0
2044  
2045 bool found;
2046 10 size_t index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
2047 10 ▶ if (index >= map->capacity) return map->capacity;
Branch: 1 branch
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 10 10
2048  
2049 10 ▶ if (found) {
Branch: 1 branch
BranchTrueFalseTotal
if (found) { 4 6 10
2050 4 ▶ if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
Branch: 2 branches
BranchTrueFalseTotal
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 3 1 4
if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) && 1 2 3
2051 1 ▶ (uint32_t)time(NULL) > map->expires_at[index]) {
Branch: 1 branch
BranchTrueFalseTotal
(uint32_t)time(NULL) > map->expires_at[index]) { 1 0 1
2052 1 HM_FN(expire_at)(map, index, true);
2053 1 found = false;
2054 1 index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
2055 1 ▶ if (index >= map->capacity) return map->capacity;
Branch: 1 branch
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 1 1
2056 }
2057 }
2058  
2059 10 ▶ if (found) {
Branch: 1 branch
BranchTrueFalseTotal
if (found) { 3 7 10
2060 3 *was_found = true;
2061 3 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
Branch: 1 branch
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index); 0 3 3
2062 3 return index;
2063 }
2064  
2065 7 ▶ if (map->max_size > 0 && map->size >= map->max_size) {
Branch: 2 branches
BranchTrueFalseTotal
if (map->max_size > 0 && map->size >= map->max_size) { 0 7 7
if (map->max_size > 0 && map->size >= map->max_size) { 0 0 0
2066 0 HM_FN(lru_evict_one)(map);
2067 0 index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
2068 0 ▶ if (index >= map->capacity) return map->capacity;
Branch: 1 branch
BranchTrueFalseTotal
if (index >= map->capacity) return map->capacity; 0 0 0
2069 }
2070  
2071 7 ▶ HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity);
Branch: 3 branches
BranchTrueFalseTotal
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 7 7
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity); 0 0 0
2072  
2073 7 char* new_key = (char*)malloc(key_len + 1);
2074 7 ▶ if (!new_key) return map->capacity;
Branch: 1 branch
BranchTrueFalseTotal
if (!new_key) return map->capacity; 0 7 7
2075 7 memcpy(new_key, key, key_len);
2076 7 new_key[key_len] = '\0';
2077  
2078 7 ▶ if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--;
Branch: 1 branch
BranchTrueFalseTotal
if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--; 1 6 7
2079 7 map->size++;
2080 7 map->nodes[index].key = new_key;
2081 7 ▶ map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8);
Branch: 1 branch
BranchTrueFalseTotal
map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8); 0 7 7
2082 7 map->nodes[index].key_hash = key_hash;
2083 7 map->nodes[index].value = def_val;
2084  
2085 7 ▶ if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
Branch: 1 branch
BranchTrueFalseTotal
if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index); 0 7 7
2086 7 ▶ HM_APPLY_ENTRY_TTL(map, index, entry_ttl);
Branch: 3 branches
BranchTrueFalseTotal
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 6 1 7
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 6 0 6
HM_APPLY_ENTRY_TTL(map, index, entry_ttl); 2 4 6
2087  
2088 7 return index;
2089 }
2090 #else
2091 9 static size_t HM_FN(get_or_set)(HM_MAP_TYPE* map,
2092 const char* key, uint32_t key_len, uint32_t key_hash, bool key_utf8,
2093 HM_INT_TYPE def_val, uint32_t entry_ttl, bool* was_found) {
2094 9 *was_found = false;
2095 9 if (!map || !key) return map ? map->capacity : 0;
2096  
2097 9 HM_ENSURE_CAPACITY(map, map->capacity);
2098  
2099 bool found;
2100 9 size_t index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
2101 9 if (index >= map->capacity) return map->capacity;
2102  
2103 9 if (found) {
2104 3 if (HM_UNLIKELY(map->expires_at && map->expires_at[index]) &&
2105 0 (uint32_t)time(NULL) > map->expires_at[index]) {
2106 0 HM_FN(expire_at)(map, index, true);
2107 0 found = false;
2108 0 index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
2109 0 if (index >= map->capacity) return map->capacity;
2110 }
2111 }
2112  
2113 9 if (found) {
2114 3 *was_found = true;
2115 3 if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_promote)(map, (uint32_t)index);
2116 3 return index;
2117 }
2118  
2119 6 if (map->max_size > 0 && map->size >= map->max_size) {
2120 0 HM_FN(lru_evict_one)(map);
2121 0 index = HM_FN(find_slot_for_insert)(map, key, key_len, key_hash, &found);
2122 0 if (index >= map->capacity) return map->capacity;
2123 }
2124  
2125 6 HM_LAZY_ALLOC_EXPIRES(map, entry_ttl, map->capacity);
2126  
2127 6 char* new_key = (char*)malloc(key_len + 1);
2128 6 if (!new_key) return map->capacity;
2129 6 memcpy(new_key, key, key_len);
2130 6 new_key[key_len] = '\0';
2131  
2132 6 if (HM_SLOT_IS_TOMBSTONE(&map->nodes[index])) map->tombstones--;
2133 6 map->size++;
2134 6 map->nodes[index].key = new_key;
2135 6 map->nodes[index].key_len = HM_PACK_LEN(key_len, key_utf8);
2136 6 map->nodes[index].key_hash = key_hash;
2137 6 map->nodes[index].value = def_val;
2138  
2139 6 if (HM_UNLIKELY(map->lru_prev)) HM_FN(lru_push_front)(map, (uint32_t)index);
2140 6 HM_APPLY_ENTRY_TTL(map, index, entry_ttl);
2141  
2142 6 return index;
2143 }
2144 #endif
2145  
2146 #endif /* HM_KEY_IS_INT for get_or_set */
2147  
2148 /* ---- Cleanup macros for next inclusion ---- */
2149  
2150 #undef HM_SLOT_IS_EMPTY
2151 #undef HM_SLOT_IS_TOMBSTONE
2152 #undef HM_SLOT_IS_LIVE
2153 #ifdef HM_KEY_IS_INT
2154 #undef HM_EMPTY_KEY
2155 #undef HM_TOMBSTONE_KEY
2156 #undef HM_IS_RESERVED_KEY
2157 #endif
2158  
2159 #undef HM_PREFIX
2160 #undef HM_NODE_TYPE
2161 #undef HM_MAP_TYPE
2162 #undef HM_FN
2163 #undef HM_PASTE
2164 #undef HM_PASTE2
2165  
2166 #undef HM_KEY_IS_INT
2167 #undef HM_VALUE_IS_STR
2168 #undef HM_VALUE_IS_SV
2169 #undef HM_HAS_COUNTERS
2170  
2171 #undef HM_INT_TYPE
2172 #undef HM_INT_MIN
2173 #undef HM_INT_MAX
« xs/ss.xsi ↑ Summary xs/ii.xsi »