include/hamt/hamt_iter.h

filter: Statementstmt 100% 20 / 20 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 28 / 28 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/hamt/hamt_hash.h ↑ Summary xs/ops.xs »
1 #ifndef HAMT_ITER_H
2 #define HAMT_ITER_H
3  
4 /* Every entry of a trie, once each. A node's own entries come first, in
5 * slot order, and then each child in slot order, so the order is the same
6 * every time for the same trie and two tries of the same shape are walked
7 * in step.
8 *
9 * The iterator borrows the root. Whoever walks holds a reference to it for
10 * as long as the walk lasts; since nothing reachable from a root ever
11 * changes, nothing else can go wrong underneath it. */
12  
13 typedef struct hamt_iter {
14 const hamt_node *node[HAMT_MAX_DEPTH + 1];
15 uint32_t pos[HAMT_MAX_DEPTH + 1];
16 int depth; /* -1 when there is nothing left */
17 } hamt_iter;
18  
19 24091 static void hamt_iter_init(hamt_iter *it, const hamt_node *root) {
20 24091 ▶ it->depth = root ? 0 : -1;
Branch: 1 branch
BranchTrueFalseTotal
it->depth = root ? 0 : -1; 23158 933 24091
21 24091 it->node[0] = root;
22 24091 it->pos[0] = 0;
23 24091 }
24  
25 1968898 static hamt_entry *hamt_iter_next(hamt_iter *it) {
26 6378285 ▶ while (it->depth >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (it->depth >= 0) { 6356403 21882 6378285
27 6356403 const hamt_node *n = it->node[it->depth];
28 6356403 uint32_t p = it->pos[it->depth];
29  
30 6356403 ▶ if (p < hamt_node_ndata(n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (p < hamt_node_ndata(n)) { 1947016 4409387 6356403
31 1947016 it->pos[it->depth] = p + 1;
32 1947016 return (hamt_entry *)n->slot[p];
33 }
34 4409387 ▶ if (p < hamt_node_nslots(n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (p < hamt_node_nslots(n)) { 2194947 2214440 4409387
35 2194947 it->pos[it->depth] = p + 1;
36 2194947 it->depth++;
37 2194947 it->node[it->depth] = (const hamt_node *)n->slot[p];
38 2194947 it->pos[it->depth] = 0;
39 2194947 continue;
40 }
41 2214440 it->depth--;
42 }
43 21882 return NULL;
44 }
45  
46 #endif
« include/hamt/hamt_hash.h ↑ Summary xs/ops.xs »