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

Function intmap_add_

ccan/ccan/intmap/intmap.c:82–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82bool intmap_add_(struct intmap *map, intmap_index_t index, const void *value)
83{
84 struct intmap *n;
85
86 assert(value);
87
88 /* Empty map? */
89 if (intmap_empty_(map)) {
90 map->u.i = index;
91 map->v = (void *)value;
92 return true;
93 }
94
95 n = map;
96 /* Anything with NULL value is a node. */
97 while (!n->v) {
98 int crit = critbit(n);
99 intmap_index_t mask = prefix_mask(crit);
100 u8 direction = (index >> crit) & 1;
101
102 if ((index & mask) != (n->u.n->prefix_and_critbit & mask))
103 return split_node(n, n->u.n->prefix_and_critbit & mask,
104 index, value);
105 n = &n->u.n->child[direction];
106 }
107
108 if (index == n->u.i) {
109 errno = EEXIST;
110 return false;
111 }
112
113 return split_node(n, n->u.i, index, value);
114}
115
116void *intmap_del_(struct intmap *map, intmap_index_t index)
117{

Callers

nothing calls this directly

Calls 4

intmap_empty_Function · 0.85
critbitFunction · 0.85
prefix_maskFunction · 0.85
split_nodeFunction · 0.85

Tested by

no test coverage detected