MCPcopy Create free account
hub / github.com/ElementsProject/lightning / split_node

Function split_node

ccan/ccan/intmap/intmap.c:53–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53static bool split_node(struct intmap *n, intmap_index_t nodeindex,
54 intmap_index_t index, const void *value)
55{
56 struct node *newn;
57 int new_dir;
58
59 /* Find highest bit where they differ. */
60 unsigned int critbit = bitops_hs64(nodeindex ^ index);
61 assert(critbit < CHAR_BIT*sizeof(index));
62
63 /* Which direction do we go at this bit? */
64 new_dir = (index >> critbit) & 1;
65
66 /* Allocate new node. */
67 newn = malloc(sizeof(*newn));
68 if (!newn) {
69 errno = ENOMEM;
70 return false;
71 }
72 newn->prefix_and_critbit = prefix_and_critbit(index, critbit);
73 newn->child[new_dir].v = (void *)value;
74 newn->child[new_dir].u.i = index;
75 newn->child[!new_dir] = *n;
76
77 n->u.n = newn;
78 n->v = NULL;
79 return true;
80}
81
82bool intmap_add_(struct intmap *map, intmap_index_t index, const void *value)
83{

Callers 1

intmap_add_Function · 0.85

Calls 2

bitops_hs64Function · 0.85
prefix_and_critbitFunction · 0.85

Tested by

no test coverage detected