| 51 | } |
| 52 | |
| 53 | static bool split_node(struct intmap *n, intmap_index_t nodeindex, |
| 54 | intmap_index_t index, const void *value) |
| 55 | { |
| 56 | struct node *newn; |
| 57 | int new_dir; |
| 58 | |
| 59 | /* Find highest bit where they differ. */ |
| 60 | unsigned int critbit = bitops_hs64(nodeindex ^ index); |
| 61 | assert(critbit < CHAR_BIT*sizeof(index)); |
| 62 | |
| 63 | /* Which direction do we go at this bit? */ |
| 64 | new_dir = (index >> critbit) & 1; |
| 65 | |
| 66 | /* Allocate new node. */ |
| 67 | newn = malloc(sizeof(*newn)); |
| 68 | if (!newn) { |
| 69 | errno = ENOMEM; |
| 70 | return false; |
| 71 | } |
| 72 | newn->prefix_and_critbit = prefix_and_critbit(index, critbit); |
| 73 | newn->child[new_dir].v = (void *)value; |
| 74 | newn->child[new_dir].u.i = index; |
| 75 | newn->child[!new_dir] = *n; |
| 76 | |
| 77 | n->u.n = newn; |
| 78 | n->v = NULL; |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | bool intmap_add_(struct intmap *map, intmap_index_t index, const void *value) |
| 83 | { |
no test coverage detected