include/hamt/hamt_mut.h

filter: Statementstmt 100% 218 / 218 Branchbran 95.9% 114 / 122 (3 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 98.5% 332 / 340 (3 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/hamt/hamt_node.h ↑ Summary include/hamt/hamt_vec.h »
1 #ifndef HAMT_MUT_H
2 #define HAMT_MUT_H
3  
4 /* Insert and delete that change a trie where it stands, wherever that is
5 * safe, and copy only where it is not.
6 *
7 * WHEN IT IS SAFE. A node may be changed in place exactly when its
8 * reference count is one. The caller of these functions owns one reference
9 * to the root and hands it over; if that is the only reference there is,
10 * nobody else can reach the root, so nobody else can see it change. The
11 * same holds one level down: a child with a count of one is pointed at by
12 * that parent alone, and the walk only reaches it through a parent it has
13 * just found to be its own. A node with any other count is shared with
14 * something - an older version, a snapshot, a walk in progress - and is
15 * copied instead; the copy takes its own reference to each child, which
16 * makes every child shared too, so everything under a shared node is copied
17 * in turn without anything having to say so.
18 *
19 * This is why a batch of updates on a fresh handle costs one path of copies
20 * for the first update and almost nothing for the rest: after the first,
21 * the path is the handle's alone.
22 *
23 * It rests on one rule that every caller keeps: NOBODY HOLDS A NODE WITHOUT
24 * COUNTING IT. A pointer kept across a call here without a reference of its
25 * own is a pointer to something that may have been changed or freed.
26 *
27 * THE DISPLACED ENTRY. An update displaces at most one entry: the one whose
28 * value is replaced, or the one deleted. Releasing it can run a value's
29 * destructor, which can call back into the very handle being updated, so it
30 * is not released here. It is handed back through `dead`, with a reference,
31 * for the caller to release once the new root is in place.
32 *
33 * NO MEMORY. Every function either does all of its work or none: on failure
34 * the trie is exactly as it was and the caller still owns the reference it
35 * passed in. Nothing is changed in place until every allocation the change
36 * needs has succeeded. */
37  
38 #define HAMT_EDITABLE(n) ((n)->refcnt == 1)
39  
40 /* The node with an entry added at a position that held nothing. If it has
41 * room, it is changed where it stands and comes back itself. If not, it is
42 * a new allocation that takes over the old node's references rather than
43 * adding to them, and the old node's memory is freed. NULL when there is no
44 * memory, with the node untouched. */
45 625043 static hamt_node *hamt_node_add_entry_move(void *cx, hamt_node *n, uint32_t bit,
46 hamt_entry *e) {
47 625043 uint32_t N = hamt_node_nslots(n);
48 625043 uint32_t di = hamt_popcnt32(n->datamap & (bit - 1));
49 hamt_node *r;
50  
51 /* Room for one more where it stands: nothing is allocated. */
52 625043 ▶ if (HAMT_NODE_ROOM(N + 1) == HAMT_NODE_ROOM(N) && N) { /* # uncoverable condition right count:2 */
Branch: 2 branches
BranchTrueFalseTotal
if (HAMT_NODE_ROOM(N + 1) == HAMT_NODE_ROOM(N) && N) { /* # uncoverable condition right count:2 */ 491952 133091 625043
if (HAMT_NODE_ROOM(N + 1) == HAMT_NODE_ROOM(N) && N) { /* # uncoverable condition right count:2 */ 491952 0 491952
53 491952 memmove(n->slot + di + 1, n->slot + di, (size_t)(N - di) * sizeof(void *));
54 491952 n->slot[di] = hamt_entry_retain(e);
55 491952 n->datamap |= bit;
56 491952 return n;
57 }
58 133091 r = hamt_node_new(cx, N + 1);
59 133091 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 309 132782 133091
60 132782 r->datamap = n->datamap | bit;
61 132782 r->nodemap = n->nodemap;
62 132782 memcpy(r->slot, n->slot, (size_t)di * sizeof(void *));
63 132782 r->slot[di] = hamt_entry_retain(e);
64 132782 memcpy(r->slot + di + 1, n->slot + di, (size_t)(N - di) * sizeof(void *));
65 132782 ▶ HAMT_FREE(cx, n, HAMT_NODE_BYTES(N));
Branch: 1 branch
BranchTrueFalseTotal
HAMT_FREE(cx, n, HAMT_NODE_BYTES(N)); 132782 0 132782
66 132782 return r;
67 }
68  
69 /* The node without the entry at a position, the same way. The entry is
70 * handed back with the reference the node held. */
71 13202 static hamt_node *hamt_node_drop_entry_move(void *cx, hamt_node *n, uint32_t bit,
72 hamt_entry **dropped) {
73 13202 uint32_t N = hamt_node_nslots(n);
74 13202 uint32_t di = hamt_popcnt32(n->datamap & (bit - 1));
75 hamt_node *r;
76  
77 /* One fewer still needs the room it has: it stays where it is. */
78 13202 ▶ if (HAMT_NODE_ROOM(N - 1) == HAMT_NODE_ROOM(N)) {
Branch: 1 branch
BranchTrueFalseTotal
if (HAMT_NODE_ROOM(N - 1) == HAMT_NODE_ROOM(N)) { 10287 2915 13202
79 10287 *dropped = (hamt_entry *)n->slot[di];
80 10287 memmove(n->slot + di, n->slot + di + 1, (size_t)(N - 1 - di) * sizeof(void *));
81 10287 n->datamap &= ~bit;
82 10287 return n;
83 }
84 2915 r = hamt_node_new(cx, N - 1);
85 2915 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 79 2836 2915
86 2836 r->datamap = n->datamap & ~bit;
87 2836 r->nodemap = n->nodemap;
88 2836 *dropped = (hamt_entry *)n->slot[di];
89 2836 memcpy(r->slot, n->slot, (size_t)di * sizeof(void *));
90 2836 memcpy(r->slot + di, n->slot + di + 1, (size_t)(N - 1 - di) * sizeof(void *));
91 2836 ▶ HAMT_FREE(cx, n, HAMT_NODE_BYTES(N));
Branch: 1 branch
BranchTrueFalseTotal
HAMT_FREE(cx, n, HAMT_NODE_BYTES(N)); 2836 0 2836
92 2836 return r;
93 }
94  
95 /* Same size, so no allocation: the entry at a position gives way to a
96 * child, which takes over the caller's reference. The entry is handed back
97 * with the reference the node held. */
98 239419 static hamt_entry *hamt_node_entry_to_child_here(hamt_node *n, uint32_t bit,
99 hamt_node *child) {
100 239419 uint32_t N = hamt_node_nslots(n);
101 239419 uint32_t di = hamt_popcnt32(n->datamap & (bit - 1));
102 239419 uint32_t ci = N - 1 - hamt_popcnt32(n->nodemap & (bit - 1));
103 239419 hamt_entry *old = (hamt_entry *)n->slot[di];
104 239419 memmove(n->slot + di, n->slot + di + 1, (size_t)(ci - di) * sizeof(void *));
105 239419 n->slot[ci] = child;
106 239419 n->datamap &= ~bit;
107 239419 n->nodemap |= bit;
108 239419 return old;
109 }
110  
111 /* And back: the child at a position gives way to an entry, which takes over
112 * the caller's reference. The child is handed back with the reference the
113 * node held. */
114 6225 static hamt_node *hamt_node_child_to_entry_here(hamt_node *n, uint32_t bit,
115 hamt_entry *e) {
116 6225 uint32_t N = hamt_node_nslots(n);
117 6225 uint32_t di = hamt_popcnt32(n->datamap & (bit - 1));
118 6225 uint32_t ci = N - 1 - hamt_popcnt32(n->nodemap & (bit - 1));
119 6225 hamt_node *old = (hamt_node *)n->slot[ci];
120 6225 memmove(n->slot + di + 1, n->slot + di, (size_t)(ci - di) * sizeof(void *));
121 6225 n->slot[di] = e;
122 6225 n->datamap |= bit;
123 6225 n->nodemap &= ~bit;
124 6225 return old;
125 }
126  
127 /* Takes over the caller's reference to `n` and returns a node the caller
128 * owns one reference to, which may be `n` itself. NULL means no memory: `n`
129 * is untouched and still the caller's. */
130 3882477 static hamt_node *hamt_node_put_mut(void *cx, hamt_node *n, unsigned depth,
131 hamt_entry *e, int *added, hamt_entry **dead) {
132 3882477 int edit = HAMT_EDITABLE(n);
133 uint32_t bit, i;
134 hamt_node *r;
135  
136 3882477 ▶ if (n->ncoll) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->ncoll) { 169991 3712486 3882477
137 1977232 ▶ for (i = 0; i < n->ncoll; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n->ncoll; i++) { 1827010 150222 1977232
138 1827010 hamt_entry *old = (hamt_entry *)n->slot[i];
139 1827010 ▶ if (!hamt_entry_key_eq(old, e->key, e->klen, e->utf8, e->hash)) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!hamt_entry_key_eq(old, e->key, e->klen, e->utf8, e->hash)) continue; 1807241 19769 1827010
140 19769 ▶ if (old == e || old->val == e->val) return n; /* # uncoverable condition left count:1 */
Branch: 2 branches
BranchTrueFalseTotal
if (old == e || old->val == e->val) return n; /* # uncoverable condition left count:1 */ 19769 0 19769
if (old == e || old->val == e->val) return n; /* # uncoverable condition left count:1 */ 119 19650 19769
141 19650 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 5557 14093 19650
142 5557 n->slot[i] = hamt_entry_retain(e);
143 5557 *dead = old;
144 5557 return n;
145 }
146 14093 r = hamt_node_with_slot(cx, n, i, e, HAMT_NO_SKIP);
147 14093 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 1 14092 14093
148 14092 *dead = hamt_entry_retain(old);
149 14092 hamt_node_release(cx, n);
150 14092 return r;
151 }
152 /* A collision node is rare enough to grow by copying whether or not
153 * it is ours. The copy holds every entry, so letting the old node
154 * go releases nothing that matters. */
155 150222 r = hamt_node_coll_add(cx, n, e);
156 150222 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 16 150206 150222
157 150206 *added = 1;
158 150206 hamt_node_release(cx, n);
159 150206 return r;
160 }
161  
162 3712486 bit = HAMT_BIT(e->hash, depth);
163  
164 3712486 ▶ if (n->datamap & bit) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->datamap & bit) { 295593 3416893 3712486
165 295593 uint32_t di = hamt_popcnt32(n->datamap & (bit - 1));
166 295593 hamt_entry *old = (hamt_entry *)n->slot[di];
167 hamt_node *sub;
168  
169 295593 ▶ if (hamt_entry_key_eq(old, e->key, e->klen, e->utf8, e->hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if (hamt_entry_key_eq(old, e->key, e->klen, e->utf8, e->hash)) { 45450 250143 295593
170 45450 ▶ if (old == e || old->val == e->val) return n; /* # uncoverable condition left count:1 */
Branch: 2 branches
BranchTrueFalseTotal
if (old == e || old->val == e->val) return n; /* # uncoverable condition left count:1 */ 45450 0 45450
if (old == e || old->val == e->val) return n; /* # uncoverable condition left count:1 */ 401 45049 45450
171 45049 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 14980 30069 45049
172 14980 n->slot[di] = hamt_entry_retain(e);
173 14980 *dead = old;
174 14980 return n;
175 }
176 30069 r = hamt_node_with_slot(cx, n, di, e, HAMT_NO_SKIP);
177 30069 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 54 30015 30069
178 30015 *dead = hamt_entry_retain(old);
179 30015 hamt_node_release(cx, n);
180 30015 return r;
181 }
182  
183 /* Two keys at one position. The subtree that holds both takes its
184 * own reference to each, so the entry leaving this node is not
185 * displaced, only moved down. */
186 250143 sub = hamt_node_pair(cx, old, e, depth + 1);
187 250143 ▶ if (!sub) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!sub) return NULL; 521 249622 250143
188 249622 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 239419 10203 249622
189 239419 hamt_entry_release(cx, hamt_node_entry_to_child_here(n, bit, sub));
190 239419 *added = 1;
191 239419 return n;
192 }
193 10203 r = hamt_node_entry_to_child(cx, n, bit, sub);
194 10203 ▶ if (!r) { hamt_node_release(cx, sub); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { hamt_node_release(cx, sub); return NULL; } 24 10179 10203
195 10179 *added = 1;
196 10179 hamt_node_release(cx, n);
197 10179 return r;
198 }
199  
200 3416893 ▶ if (n->nodemap & bit) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->nodemap & bit) { 2760190 656703 3416893
201 2760190 uint32_t ci = hamt_node_nslots(n) - 1 - hamt_popcnt32(n->nodemap & (bit - 1));
202 2760190 hamt_node *child = (hamt_node *)n->slot[ci];
203 hamt_node *sub;
204  
205 2760190 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 2460782 299408 2760190
206 /* This node's reference to the child is the one handed down. */
207 2460782 sub = hamt_node_put_mut(cx, child, depth + 1, e, added, dead);
208 2460782 ▶ if (!sub) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!sub) return NULL; 908 2459874 2460782
209 2459874 n->slot[ci] = sub;
210 2459874 return n;
211 }
212  
213 /* A shared node's reference to its child is not ours to hand down,
214 * so the child goes down with one of its own - which makes it
215 * shared, and so copied rather than changed. */
216 299408 hamt_node_retain(child);
217 299408 sub = hamt_node_put_mut(cx, child, depth + 1, e, added, dead);
218 299408 ▶ if (!sub) { hamt_node_release(cx, child); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!sub) { hamt_node_release(cx, child); return NULL; } 272 299136 299408
219 299136 ▶ if (sub == child) {
Branch: 1 branch
BranchTrueFalseTotal
if (sub == child) { 1578 297558 299136
220 1578 hamt_node_release(cx, sub);
221 1578 return n;
222 }
223 297558 r = hamt_node_with_slot(cx, n, ci, sub, ci);
224 297558 ▶ if (!r) {
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { 56 297502 297558
225 /* Everything below was a copy, so it can all be let go. */
226 56 hamt_node_release(cx, sub);
227 56 ▶ if (*dead) { hamt_entry_release(cx, *dead); *dead = NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (*dead) { hamt_entry_release(cx, *dead); *dead = NULL; } 18 38 56
228 56 *added = 0;
229 56 return NULL;
230 }
231 297502 hamt_node_release(cx, n);
232 297502 return r;
233 }
234  
235 625043 r = edit ? hamt_node_add_entry_move(cx, n, bit, e)
236 656703 ▶ : hamt_node_add_entry(cx, n, bit, e);
Branch: 1 branch
BranchTrueFalseTotal
: hamt_node_add_entry(cx, n, bit, e); 625043 31660 656703
237 656703 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 400 656303 656703
238 656303 *added = 1;
239 656303 ▶ if (!edit) hamt_node_release(cx, n);
Branch: 1 branch
BranchTrueFalseTotal
if (!edit) hamt_node_release(cx, n); 31569 624734 656303
240 656303 return r;
241 }
242  
243 /* Puts an entry into the trie at *rootp, which the caller owns one
244 * reference to before and after; the pointer may change. The entry is
245 * shared: the caller keeps its own reference.
246 *
247 * `*added` is 1 for a new key. `*dead` is the entry this one displaced, if
248 * any, for the caller to release AFTER it has put the new root wherever it
249 * keeps its root.
250 *
251 * 0, or -1 for no memory with everything as it was. */
252 1130131 static int hamt_map_put_mut(void *cx, hamt_node **rootp, hamt_entry *e,
253 int *added, hamt_entry **dead) {
254 hamt_node *r;
255  
256 1130131 *added = 0;
257 1130131 *dead = NULL;
258 1130131 ▶ if (!*rootp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!*rootp) { 7844 1122287 1130131
259 7844 r = hamt_node_new(cx, 1);
260 7844 ▶ if (!r) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return -1; 12 7832 7844
261 7832 r->datamap = HAMT_BIT(e->hash, 0);
262 7832 r->slot[0] = hamt_entry_retain(e);
263 7832 *added = 1;
264 7832 *rootp = r;
265 7832 return 0;
266 }
267 1122287 r = hamt_node_put_mut(cx, *rootp, 0, e, added, dead);
268 1122287 ▶ if (!r) { *added = 0; return -1; }
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { *added = 0; return -1; } 1072 1121215 1122287
269 1121215 *rootp = r;
270 1121215 return 0;
271 }
272  
273 /* Takes over the caller's reference to `n` when it removes something
274 * (HAMT_DEL_DONE) and returns what replaces it, which may be `n` itself, or
275 * NULL for a root that is now empty. HAMT_DEL_ABSENT returns `n`, untouched
276 * and still the caller's. HAMT_DEL_OOM returns NULL, likewise. */
277 341588 static hamt_node *hamt_node_del_mut(void *cx, hamt_node *n, unsigned depth,
278 const char *key, size_t klen, int utf8,
279 uint64_t hash, int *status, hamt_entry **dead) {
280 341588 int edit = HAMT_EDITABLE(n);
281 uint32_t bit, i;
282 hamt_node *r;
283  
284 341588 ▶ if (n->ncoll) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->ncoll) { 18593 322995 341588
285 335749 ▶ for (i = 0; i < n->ncoll; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n->ncoll; i++) { 328883 6866 335749
286 328883 hamt_entry *old = (hamt_entry *)n->slot[i];
287 328883 ▶ if (!hamt_entry_key_eq(old, key, klen, utf8, hash)) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!hamt_entry_key_eq(old, key, klen, utf8, hash)) continue; 317156 11727 328883
288 11727 r = hamt_node_coll_drop(cx, n, i);
289 11727 ▶ if (!r) { *status = HAMT_DEL_OOM; return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { *status = HAMT_DEL_OOM; return NULL; } 7 11720 11727
290 11720 *dead = hamt_entry_retain(old);
291 11720 *status = HAMT_DEL_DONE;
292 11720 hamt_node_release(cx, n);
293 11720 return r;
294 }
295 6866 *status = HAMT_DEL_ABSENT;
296 6866 return n;
297 }
298  
299 322995 bit = HAMT_BIT(hash, depth);
300  
301 322995 ▶ if (n->datamap & bit) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->datamap & bit) { 36883 286112 322995
302 36883 hamt_entry *old = (hamt_entry *)
303 36883 n->slot[hamt_popcnt32(n->datamap & (bit - 1))];
304  
305 36883 ▶ if (!hamt_entry_key_eq(old, key, klen, utf8, hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hamt_entry_key_eq(old, key, klen, utf8, hash)) { 4436 32447 36883
306 4436 *status = HAMT_DEL_ABSENT;
307 4436 return n;
308 }
309 32447 ▶ if (hamt_node_nslots(n) == 1) { /* the last of a root */
Branch: 1 branch
BranchTrueFalseTotal
if (hamt_node_nslots(n) == 1) { /* the last of a root */ 13 32434 32447
310 13 *dead = hamt_entry_retain(old);
311 13 *status = HAMT_DEL_DONE;
312 13 hamt_node_release(cx, n);
313 13 return NULL;
314 }
315 32434 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 13202 19232 32434
316 13202 r = hamt_node_drop_entry_move(cx, n, bit, dead);
317 13202 ▶ if (!r) { *status = HAMT_DEL_OOM; return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { *status = HAMT_DEL_OOM; return NULL; } 79 13123 13202
318 13123 *status = HAMT_DEL_DONE;
319 13123 return r;
320 }
321 19232 r = hamt_node_drop_entry(cx, n, bit);
322 19232 ▶ if (!r) { *status = HAMT_DEL_OOM; return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { *status = HAMT_DEL_OOM; return NULL; } 134 19098 19232
323 19098 *dead = hamt_entry_retain(old);
324 19098 *status = HAMT_DEL_DONE;
325 19098 hamt_node_release(cx, n);
326 19098 return r;
327 }
328  
329 286112 ▶ if (n->nodemap & bit) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->nodemap & bit) { 277532 8580 286112
330 277532 uint32_t ci = hamt_node_nslots(n) - 1 - hamt_popcnt32(n->nodemap & (bit - 1));
331 277532 hamt_node *child = (hamt_node *)n->slot[ci];
332 hamt_node *sub;
333  
334 277532 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 94988 182544 277532
335 94988 sub = hamt_node_del_mut(cx, child, depth + 1, key, klen, utf8, hash,
336 status, dead);
337 94988 ▶ if (*status != HAMT_DEL_DONE) return *status == HAMT_DEL_ABSENT ? n : NULL;
Branch: 2 branches
BranchTrueFalseTotal
if (*status != HAMT_DEL_DONE) return *status == HAMT_DEL_ABSENT ? n : NULL; 31337 63651 94988
if (*status != HAMT_DEL_DONE) return *status == HAMT_DEL_ABSENT ? n : NULL; 30990 347 31337
338 /*
339 # uncoverable branch true
340 # uncoverable condition left count:1 */
341 63651 ▶ if (!sub) HAMT_FATAL("a node below the root came back empty");
Branch: 1 branch
BranchTrueFalseTotal
if (!sub) HAMT_FATAL("a node below the root came back empty"); 0 63651 63651
342  
343 63651 ▶ if (hamt_node_is_single(sub)) {
Branch: 1 branch
BranchTrueFalseTotal
if (hamt_node_is_single(sub)) { 6225 57426 63651
344 /* The fold, where the node stands. The entry is kept alive
345 * by a reference of this node's before the child that held
346 * it is let go. */
347 6225 hamt_entry *up = hamt_entry_retain((hamt_entry *)sub->slot[0]);
348 6225 n->slot[ci] = sub;
349 6225 hamt_node_release(cx, hamt_node_child_to_entry_here(n, bit, up));
350 }
351 57426 else n->slot[ci] = sub;
352 63651 return n;
353 }
354  
355 182544 hamt_node_retain(child);
356 182544 sub = hamt_node_del_mut(cx, child, depth + 1, key, klen, utf8, hash,
357 status, dead);
358 182544 ▶ if (*status == HAMT_DEL_OOM) { hamt_node_release(cx, child); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (*status == HAMT_DEL_OOM) { hamt_node_release(cx, child); return NULL; } 172 182372 182544
359 182372 ▶ if (*status == HAMT_DEL_ABSENT) { hamt_node_release(cx, child); return n; }
Branch: 1 branch
BranchTrueFalseTotal
if (*status == HAMT_DEL_ABSENT) { hamt_node_release(cx, child); return n; } 64755 117617 182372
360 /*
361 # uncoverable branch true
362 # uncoverable condition left count:1 */
363 117617 ▶ if (!sub) HAMT_FATAL("a node below the root came back empty");
Branch: 1 branch
BranchTrueFalseTotal
if (!sub) HAMT_FATAL("a node below the root came back empty"); 0 117617 117617
364  
365 117617 r = hamt_node_is_single(sub)
366 23780 ? hamt_node_child_to_entry(cx, n, bit, (hamt_entry *)sub->slot[0])
367 117617 ▶ : hamt_node_with_slot(cx, n, ci, sub, HAMT_NO_SKIP);
Branch: 1 branch
BranchTrueFalseTotal
: hamt_node_with_slot(cx, n, ci, sub, HAMT_NO_SKIP); 23780 93837 117617
368 117617 hamt_node_release(cx, sub);
369 117617 ▶ if (!r) {
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { 40 117577 117617
370 /*
371 # uncoverable branch false
372 # uncoverable condition right count:1 */
373 40 ▶ if (*dead) { hamt_entry_release(cx, *dead); *dead = NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (*dead) { hamt_entry_release(cx, *dead); *dead = NULL; } 40 0 40
374 40 *status = HAMT_DEL_OOM;
375 40 return NULL;
376 }
377 117577 hamt_node_release(cx, n);
378 117577 return r;
379 }
380  
381 8580 *status = HAMT_DEL_ABSENT;
382 8580 return n;
383 }
384  
385 /* Takes a key out of the trie at *rootp, which the caller owns one
386 * reference to before and after; the pointer may change, and is NULL for a
387 * trie that is now empty. `*dead` is the entry removed, for the caller to
388 * release after it has put the new root wherever it keeps its root.
389 *
390 * HAMT_DEL_DONE, HAMT_DEL_ABSENT, or HAMT_DEL_OOM with everything as it
391 * was. */
392 64064 static int hamt_map_del_mut(void *cx, hamt_node **rootp, const char *key,
393 size_t klen, int utf8, uint64_t hash,
394 hamt_entry **dead) {
395 64064 int status = HAMT_DEL_ABSENT;
396 hamt_node *r;
397  
398 64064 *dead = NULL;
399 64064 ▶ if (!*rootp) return HAMT_DEL_ABSENT;
Branch: 1 branch
BranchTrueFalseTotal
if (!*rootp) return HAMT_DEL_ABSENT; 8 64056 64064
400 64056 r = hamt_node_del_mut(cx, *rootp, 0, key, klen, utf8, hash, &status, dead);
401 64056 ▶ if (status == HAMT_DEL_DONE) *rootp = r;
Branch: 1 branch
BranchTrueFalseTotal
if (status == HAMT_DEL_DONE) *rootp = r; 43914 20142 64056
402 64056 return status;
403 }
404  
405 #endif
« include/hamt/hamt_node.h ↑ Summary include/hamt/hamt_vec.h »