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 10175 static void hamt_iter_init(hamt_iter *it, const hamt_node *root) {
20 10175 ▶ it->depth = root ? 0 : -1;
Branch: 1 branch
BranchTrueFalseTotal
it->depth = root ? 0 : -1; 9242 933 10175
21 10175 it->node[0] = root;
22 10175 it->pos[0] = 0;
23 10175 }
24  
25 1698184 static hamt_entry *hamt_iter_next(hamt_iter *it) {
26 5973323 ▶ while (it->depth >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (it->depth >= 0) { 5963192 10131 5973323
27 5963192 const hamt_node *n = it->node[it->depth];
28 5963192 uint32_t p = it->pos[it->depth];
29  
30 5963192 ▶ if (p < hamt_node_ndata(n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (p < hamt_node_ndata(n)) { 1688053 4275139 5963192
31 1688053 it->pos[it->depth] = p + 1;
32 1688053 return (hamt_entry *)n->slot[p];
33 }
34 4275139 ▶ if (p < hamt_node_nslots(n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (p < hamt_node_nslots(n)) { 2132972 2142167 4275139
35 2132972 it->pos[it->depth] = p + 1;
36 2132972 it->depth++;
37 2132972 it->node[it->depth] = (const hamt_node *)n->slot[p];
38 2132972 it->pos[it->depth] = 0;
39 2132972 continue;
40 }
41 2142167 it->depth--;
42 }
43 10131 return NULL;
44 }
45  
46 #endif
« include/hamt/hamt_hash.h ↑ Summary xs/ops.xs »