include/hamt/hamt_mut.h

filter: Statementstmt 96.7% 211 / 218 Branchbran 75.4% 92 / 122 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 89.1% 303 / 340 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/hamt/hamt_vec.h ↑ Summary include/hamt/hamt_sv.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 343835 static hamt_node *hamt_node_add_entry_move(void *cx, hamt_node *n, uint32_t bit,
46 hamt_entry *e) {
47 343835 uint32_t N = hamt_node_nslots(n);
48 343835 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 343835 ▶ if (HAMT_NODE_ROOM(N + 1) == HAMT_NODE_ROOM(N) && N) {
Branch: 2 branches
BranchTrueFalseTotal
if (HAMT_NODE_ROOM(N + 1) == HAMT_NODE_ROOM(N) && N) { 269457 74378 343835
if (HAMT_NODE_ROOM(N + 1) == HAMT_NODE_ROOM(N) && N) { 269457 0 269457
53 269457 memmove(n->slot + di + 1, n->slot + di, (size_t)(N - di) * sizeof(void *));
54 269457 n->slot[di] = hamt_entry_retain(e);
55 269457 n->datamap |= bit;
56 269457 return n;
57 }
58 74378 r = hamt_node_new(cx, N + 1);
59 74378 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 0 74378 74378
60 74378 r->datamap = n->datamap | bit;
61 74378 r->nodemap = n->nodemap;
62 74378 memcpy(r->slot, n->slot, (size_t)di * sizeof(void *));
63 74378 r->slot[di] = hamt_entry_retain(e);
64 74378 memcpy(r->slot + di + 1, n->slot + di, (size_t)(N - di) * sizeof(void *));
65 74378 ▶ HAMT_FREE(cx, n, HAMT_NODE_BYTES(N));
Branch: 1 branch
BranchTrueFalseTotal
HAMT_FREE(cx, n, HAMT_NODE_BYTES(N)); 74378 0 74378
66 74378 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 2863 static hamt_node *hamt_node_drop_entry_move(void *cx, hamt_node *n, uint32_t bit,
72 hamt_entry **dropped) {
73 2863 uint32_t N = hamt_node_nslots(n);
74 2863 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 2863 ▶ if (HAMT_NODE_ROOM(N - 1) == HAMT_NODE_ROOM(N)) {
Branch: 1 branch
BranchTrueFalseTotal
if (HAMT_NODE_ROOM(N - 1) == HAMT_NODE_ROOM(N)) { 2252 611 2863
79 2252 *dropped = (hamt_entry *)n->slot[di];
80 2252 memmove(n->slot + di, n->slot + di + 1, (size_t)(N - 1 - di) * sizeof(void *));
81 2252 n->datamap &= ~bit;
82 2252 return n;
83 }
84 611 r = hamt_node_new(cx, N - 1);
85 611 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 0 611 611
86 611 r->datamap = n->datamap & ~bit;
87 611 r->nodemap = n->nodemap;
88 611 *dropped = (hamt_entry *)n->slot[di];
89 611 memcpy(r->slot, n->slot, (size_t)di * sizeof(void *));
90 611 memcpy(r->slot + di, n->slot + di + 1, (size_t)(N - 1 - di) * sizeof(void *));
91 611 ▶ HAMT_FREE(cx, n, HAMT_NODE_BYTES(N));
Branch: 1 branch
BranchTrueFalseTotal
HAMT_FREE(cx, n, HAMT_NODE_BYTES(N)); 611 0 611
92 611 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 137299 static hamt_entry *hamt_node_entry_to_child_here(hamt_node *n, uint32_t bit,
99 hamt_node *child) {
100 137299 uint32_t N = hamt_node_nslots(n);
101 137299 uint32_t di = hamt_popcnt32(n->datamap & (bit - 1));
102 137299 uint32_t ci = N - 1 - hamt_popcnt32(n->nodemap & (bit - 1));
103 137299 hamt_entry *old = (hamt_entry *)n->slot[di];
104 137299 memmove(n->slot + di, n->slot + di + 1, (size_t)(ci - di) * sizeof(void *));
105 137299 n->slot[ci] = child;
106 137299 n->datamap &= ~bit;
107 137299 n->nodemap |= bit;
108 137299 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 2957 static hamt_node *hamt_node_child_to_entry_here(hamt_node *n, uint32_t bit,
115 hamt_entry *e) {
116 2957 uint32_t N = hamt_node_nslots(n);
117 2957 uint32_t di = hamt_popcnt32(n->datamap & (bit - 1));
118 2957 uint32_t ci = N - 1 - hamt_popcnt32(n->nodemap & (bit - 1));
119 2957 hamt_node *old = (hamt_node *)n->slot[ci];
120 2957 memmove(n->slot + di + 1, n->slot + di, (size_t)(ci - di) * sizeof(void *));
121 2957 n->slot[di] = e;
122 2957 n->datamap |= bit;
123 2957 n->nodemap &= ~bit;
124 2957 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 3134893 static hamt_node *hamt_node_put_mut(void *cx, hamt_node *n, unsigned depth,
131 hamt_entry *e, int *added, hamt_entry **dead) {
132 3134893 int edit = HAMT_EDITABLE(n);
133 uint32_t bit, i;
134 hamt_node *r;
135  
136 3134893 ▶ if (n->ncoll) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->ncoll) { 169311 2965582 3134893
137 1967001 ▶ for (i = 0; i < n->ncoll; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n->ncoll; i++) { 1817475 149526 1967001
138 1817475 hamt_entry *old = (hamt_entry *)n->slot[i];
139 1817475 ▶ 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; 1797690 19785 1817475
140 19785 ▶ if (old == e || old->val == e->val) return n;
Branch: 2 branches
BranchTrueFalseTotal
if (old == e || old->val == e->val) return n; 19785 0 19785
if (old == e || old->val == e->val) return n; 116 19669 19785
141 19669 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 5475 14194 19669
142 5475 n->slot[i] = hamt_entry_retain(e);
143 5475 *dead = old;
144 5475 return n;
145 }
146 14194 r = hamt_node_with_slot(cx, n, i, e, HAMT_NO_SKIP);
147 14194 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 0 14194 14194
148 14194 *dead = hamt_entry_retain(old);
149 14194 hamt_node_release(cx, n);
150 14194 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 149526 r = hamt_node_coll_add(cx, n, e);
156 149526 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 0 149526 149526
157 149526 *added = 1;
158 149526 hamt_node_release(cx, n);
159 149526 return r;
160 }
161  
162 2965582 bit = HAMT_BIT(e->hash, depth);
163  
164 2965582 ▶ if (n->datamap & bit) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->datamap & bit) { 164289 2801293 2965582
165 164289 uint32_t di = hamt_popcnt32(n->datamap & (bit - 1));
166 164289 hamt_entry *old = (hamt_entry *)n->slot[di];
167 hamt_node *sub;
168  
169 164289 ▶ 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)) { 20962 143327 164289
170 20962 ▶ if (old == e || old->val == e->val) return n;
Branch: 2 branches
BranchTrueFalseTotal
if (old == e || old->val == e->val) return n; 20962 0 20962
if (old == e || old->val == e->val) return n; 162 20800 20962
171 20800 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 3983 16817 20800
172 3983 n->slot[di] = hamt_entry_retain(e);
173 3983 *dead = old;
174 3983 return n;
175 }
176 16817 r = hamt_node_with_slot(cx, n, di, e, HAMT_NO_SKIP);
177 16817 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 0 16817 16817
178 16817 *dead = hamt_entry_retain(old);
179 16817 hamt_node_release(cx, n);
180 16817 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 143327 sub = hamt_node_pair(cx, old, e, depth + 1);
187 143327 ▶ if (!sub) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!sub) return NULL; 0 143327 143327
188 143327 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 137299 6028 143327
189 137299 hamt_entry_release(cx, hamt_node_entry_to_child_here(n, bit, sub));
190 137299 *added = 1;
191 137299 return n;
192 }
193 6028 r = hamt_node_entry_to_child(cx, n, bit, sub);
194 6028 ▶ if (!r) { hamt_node_release(cx, sub); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { hamt_node_release(cx, sub); return NULL; } 0 6028 6028
195 6028 *added = 1;
196 6028 hamt_node_release(cx, n);
197 6028 return r;
198 }
199  
200 2801293 ▶ if (n->nodemap & bit) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->nodemap & bit) { 2444233 357060 2801293
201 2444233 uint32_t ci = hamt_node_nslots(n) - 1 - hamt_popcnt32(n->nodemap & (bit - 1));
202 2444233 hamt_node *child = (hamt_node *)n->slot[ci];
203 hamt_node *sub;
204  
205 2444233 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 2149206 295027 2444233
206 /* This node's reference to the child is the one handed down. */
207 2149206 sub = hamt_node_put_mut(cx, child, depth + 1, e, added, dead);
208 2149206 ▶ if (!sub) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!sub) return NULL; 0 2149206 2149206
209 2149206 n->slot[ci] = sub;
210 2149206 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 295027 hamt_node_retain(child);
217 295027 sub = hamt_node_put_mut(cx, child, depth + 1, e, added, dead);
218 295027 ▶ if (!sub) { hamt_node_release(cx, child); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!sub) { hamt_node_release(cx, child); return NULL; } 0 295027 295027
219 295027 ▶ if (sub == child) {
Branch: 1 branch
BranchTrueFalseTotal
if (sub == child) { 1549 293478 295027
220 1549 hamt_node_release(cx, sub);
221 1549 return n;
222 }
223 293478 r = hamt_node_with_slot(cx, n, ci, sub, ci);
224 293478 ▶ if (!r) {
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { 0 293478 293478
225 /* Everything below was a copy, so it can all be let go. */
226 0 hamt_node_release(cx, sub);
227 0 ▶ if (*dead) { hamt_entry_release(cx, *dead); *dead = NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (*dead) { hamt_entry_release(cx, *dead); *dead = NULL; } 0 0 0
228 0 *added = 0;
229 0 return NULL;
230 }
231 293478 hamt_node_release(cx, n);
232 293478 return r;
233 }
234  
235 343835 r = edit ? hamt_node_add_entry_move(cx, n, bit, e)
236 357060 ▶ : hamt_node_add_entry(cx, n, bit, e);
Branch: 1 branch
BranchTrueFalseTotal
: hamt_node_add_entry(cx, n, bit, e); 343835 13225 357060
237 357060 ▶ if (!r) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return NULL; 0 357060 357060
238 357060 *added = 1;
239 357060 ▶ if (!edit) hamt_node_release(cx, n);
Branch: 1 branch
BranchTrueFalseTotal
if (!edit) hamt_node_release(cx, n); 13225 343835 357060
240 357060 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 694149 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 694149 *added = 0;
257 694149 *dead = NULL;
258 694149 ▶ if (!*rootp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!*rootp) { 3489 690660 694149
259 3489 r = hamt_node_new(cx, 1);
260 3489 ▶ if (!r) return -1;
Branch: 1 branch
BranchTrueFalseTotal
if (!r) return -1; 0 3489 3489
261 3489 r->datamap = HAMT_BIT(e->hash, 0);
262 3489 r->slot[0] = hamt_entry_retain(e);
263 3489 *added = 1;
264 3489 *rootp = r;
265 3489 return 0;
266 }
267 690660 r = hamt_node_put_mut(cx, *rootp, 0, e, added, dead);
268 690660 ▶ if (!r) { *added = 0; return -1; }
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { *added = 0; return -1; } 0 690660 690660
269 690660 *rootp = r;
270 690660 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 298554 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 298554 int edit = HAMT_EDITABLE(n);
281 uint32_t bit, i;
282 hamt_node *r;
283  
284 298554 ▶ if (n->ncoll) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->ncoll) { 18387 280167 298554
285 334892 ▶ for (i = 0; i < n->ncoll; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n->ncoll; i++) { 328135 6757 334892
286 328135 hamt_entry *old = (hamt_entry *)n->slot[i];
287 328135 ▶ 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; 316505 11630 328135
288 11630 r = hamt_node_coll_drop(cx, n, i);
289 11630 ▶ if (!r) { *status = HAMT_DEL_OOM; return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { *status = HAMT_DEL_OOM; return NULL; } 0 11630 11630
290 11630 *dead = hamt_entry_retain(old);
291 11630 *status = HAMT_DEL_DONE;
292 11630 hamt_node_release(cx, n);
293 11630 return r;
294 }
295 6757 *status = HAMT_DEL_ABSENT;
296 6757 return n;
297 }
298  
299 280167 bit = HAMT_BIT(hash, depth);
300  
301 280167 ▶ if (n->datamap & bit) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->datamap & bit) { 18655 261512 280167
302 18655 hamt_entry *old = (hamt_entry *)
303 18655 n->slot[hamt_popcnt32(n->datamap & (bit - 1))];
304  
305 18655 ▶ if (!hamt_entry_key_eq(old, key, klen, utf8, hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hamt_entry_key_eq(old, key, klen, utf8, hash)) { 4424 14231 18655
306 4424 *status = HAMT_DEL_ABSENT;
307 4424 return n;
308 }
309 14231 ▶ 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 */ 7 14224 14231
310 7 *dead = hamt_entry_retain(old);
311 7 *status = HAMT_DEL_DONE;
312 7 hamt_node_release(cx, n);
313 7 return NULL;
314 }
315 14224 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 2863 11361 14224
316 2863 r = hamt_node_drop_entry_move(cx, n, bit, dead);
317 2863 ▶ if (!r) { *status = HAMT_DEL_OOM; return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { *status = HAMT_DEL_OOM; return NULL; } 0 2863 2863
318 2863 *status = HAMT_DEL_DONE;
319 2863 return r;
320 }
321 11361 r = hamt_node_drop_entry(cx, n, bit);
322 11361 ▶ if (!r) { *status = HAMT_DEL_OOM; return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { *status = HAMT_DEL_OOM; return NULL; } 0 11361 11361
323 11361 *dead = hamt_entry_retain(old);
324 11361 *status = HAMT_DEL_DONE;
325 11361 hamt_node_release(cx, n);
326 11361 return r;
327 }
328  
329 261512 ▶ if (n->nodemap & bit) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->nodemap & bit) { 253566 7946 261512
330 253566 uint32_t ci = hamt_node_nslots(n) - 1 - hamt_popcnt32(n->nodemap & (bit - 1));
331 253566 hamt_node *child = (hamt_node *)n->slot[ci];
332 hamt_node *sub;
333  
334 253566 ▶ if (edit) {
Branch: 1 branch
BranchTrueFalseTotal
if (edit) { 74755 178811 253566
335 74755 sub = hamt_node_del_mut(cx, child, depth + 1, key, klen, utf8, hash,
336 status, dead);
337 74755 ▶ 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; 30922 43833 74755
if (*status != HAMT_DEL_DONE) return *status == HAMT_DEL_ABSENT ? n : NULL; 30922 0 30922
338 43833 ▶ 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 43833 43833
339  
340 43833 ▶ if (hamt_node_is_single(sub)) {
Branch: 1 branch
BranchTrueFalseTotal
if (hamt_node_is_single(sub)) { 2957 40876 43833
341 /* The fold, where the node stands. The entry is kept alive
342 * by a reference of this node's before the child that held
343 * it is let go. */
344 2957 hamt_entry *up = hamt_entry_retain((hamt_entry *)sub->slot[0]);
345 2957 n->slot[ci] = sub;
346 2957 hamt_node_release(cx, hamt_node_child_to_entry_here(n, bit, up));
347 }
348 40876 else n->slot[ci] = sub;
349 43833 return n;
350 }
351  
352 178811 hamt_node_retain(child);
353 178811 sub = hamt_node_del_mut(cx, child, depth + 1, key, klen, utf8, hash,
354 status, dead);
355 178811 ▶ 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; } 0 178811 178811
356 178811 ▶ 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; } 63165 115646 178811
357 115646 ▶ 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 115646 115646
358  
359 115646 r = hamt_node_is_single(sub)
360 24296 ? hamt_node_child_to_entry(cx, n, bit, (hamt_entry *)sub->slot[0])
361 115646 ▶ : 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); 24296 91350 115646
362 115646 hamt_node_release(cx, sub);
363 115646 ▶ if (!r) {
Branch: 1 branch
BranchTrueFalseTotal
if (!r) { 0 115646 115646
364 0 ▶ if (*dead) { hamt_entry_release(cx, *dead); *dead = NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (*dead) { hamt_entry_release(cx, *dead); *dead = NULL; } 0 0 0
365 0 *status = HAMT_DEL_OOM;
366 0 return NULL;
367 }
368 115646 hamt_node_release(cx, n);
369 115646 return r;
370 }
371  
372 7946 *status = HAMT_DEL_ABSENT;
373 7946 return n;
374 }
375  
376 /* Takes a key out of the trie at *rootp, which the caller owns one
377 * reference to before and after; the pointer may change, and is NULL for a
378 * trie that is now empty. `*dead` is the entry removed, for the caller to
379 * release after it has put the new root wherever it keeps its root.
380 *
381 * HAMT_DEL_DONE, HAMT_DEL_ABSENT, or HAMT_DEL_OOM with everything as it
382 * was. */
383 44996 static int hamt_map_del_mut(void *cx, hamt_node **rootp, const char *key,
384 size_t klen, int utf8, uint64_t hash,
385 hamt_entry **dead) {
386 44996 int status = HAMT_DEL_ABSENT;
387 hamt_node *r;
388  
389 44996 *dead = NULL;
390 44996 ▶ if (!*rootp) return HAMT_DEL_ABSENT;
Branch: 1 branch
BranchTrueFalseTotal
if (!*rootp) return HAMT_DEL_ABSENT; 8 44988 44996
391 44988 r = hamt_node_del_mut(cx, *rootp, 0, key, klen, utf8, hash, &status, dead);
392 44988 ▶ if (status == HAMT_DEL_DONE) *rootp = r;
Branch: 1 branch
BranchTrueFalseTotal
if (status == HAMT_DEL_DONE) *rootp = r; 25861 19127 44988
393 44988 return status;
394 }
395  
396 #endif
« include/hamt/hamt_vec.h ↑ Summary include/hamt/hamt_sv.h »