| 130 | } |
| 131 | |
| 132 | char *strmap_del_(struct strmap *map, const char *member, void **valuep) |
| 133 | { |
| 134 | size_t len = strlen(member); |
| 135 | const u8 *bytes = (const u8 *)member; |
| 136 | struct strmap *parent = NULL, *n; |
| 137 | const char *ret = NULL; |
| 138 | u8 direction = 0; /* prevent bogus gcc warning. */ |
| 139 | |
| 140 | /* Empty map? */ |
| 141 | if (!map->u.n) { |
| 142 | errno = ENOENT; |
| 143 | return NULL; |
| 144 | } |
| 145 | |
| 146 | /* Find closest, but keep track of parent. */ |
| 147 | n = map; |
| 148 | /* Anything with NULL value is a node. */ |
| 149 | while (!n->v) { |
| 150 | u8 c = 0; |
| 151 | |
| 152 | parent = n; |
| 153 | if (n->u.n->byte_num < len) { |
| 154 | c = bytes[n->u.n->byte_num]; |
| 155 | direction = (c >> n->u.n->bit_num) & 1; |
| 156 | } else |
| 157 | direction = 0; |
| 158 | n = &n->u.n->child[direction]; |
| 159 | } |
| 160 | |
| 161 | /* Did we find it? */ |
| 162 | if (!streq(member, n->u.s)) { |
| 163 | errno = ENOENT; |
| 164 | return NULL; |
| 165 | } |
| 166 | |
| 167 | ret = n->u.s; |
| 168 | if (valuep) |
| 169 | *valuep = n->v; |
| 170 | |
| 171 | if (!parent) { |
| 172 | /* We deleted last node. */ |
| 173 | map->u.n = NULL; |
| 174 | } else { |
| 175 | struct node *old = parent->u.n; |
| 176 | /* Raise other node to parent. */ |
| 177 | *parent = old->child[!direction]; |
| 178 | free(old); |
| 179 | } |
| 180 | |
| 181 | return (char *)ret; |
| 182 | } |
| 183 | |
| 184 | /* Defer child[1] of a node we're descending past. */ |
| 185 | static void iter_push(struct strmap_iter *it, struct strmap *slot) |
nothing calls this directly
no outgoing calls
no test coverage detected