| 114 | } |
| 115 | |
| 116 | void *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 | |
| 159 | void *intmap_first_(const struct intmap *map, intmap_index_t *indexp) |
| 160 | { |
nothing calls this directly
no test coverage detected