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

Function intmap_del_

ccan/ccan/intmap/intmap.c:116–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116void *intmap_del_(struct intmap *map, intmap_index_t index)
117{
118 struct intmap *parent = NULL, *n;
119 u8 direction;
120 void *value;
121
122 /* Empty map? */
123 if (intmap_empty_(map)) {
124 errno = ENOENT;
125 return NULL;
126 }
127
128 /* Find closest, but keep track of parent. */
129 n = map;
130 /* Anything with NULL value is a node. */
131 while (!n->v) {
132 /* FIXME: compare cmp prefix, if not equal, ENOENT */
133 parent = n;
134 direction = (index >> critbit(n)) & 1;
135 n = &n->u.n->child[direction];
136 }
137
138 /* Did we find it? */
139 if (index != n->u.i) {
140 errno = ENOENT;
141 return NULL;
142 }
143
144 value = n->v;
145
146 if (!parent) {
147 /* We deleted last node. */
148 intmap_init_(map);
149 } else {
150 struct node *old = parent->u.n;
151 /* Raise other node to parent. */
152 *parent = old->child[!direction];
153 free(old);
154 }
155 errno = 0;
156 return value;
157}
158
159void *intmap_first_(const struct intmap *map, intmap_index_t *indexp)
160{

Callers

nothing calls this directly

Calls 3

intmap_empty_Function · 0.85
critbitFunction · 0.85
intmap_init_Function · 0.85

Tested by

no test coverage detected