| 80 | } |
| 81 | |
| 82 | bool 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 | |
| 116 | void *intmap_del_(struct intmap *map, intmap_index_t index) |
| 117 | { |
nothing calls this directly
no test coverage detected