* How to consolidate an int_node: * If there are > 1 non-NULL entries, give up and return non-zero. * Otherwise replace the int_node at the given index in the given parent node * with the only NOTE entry (or a NULL entry if no entries) from the given * tree, and return 0. */
| 167 | * tree, and return 0. |
| 168 | */ |
| 169 | static int note_tree_consolidate(struct int_node *tree, |
| 170 | struct int_node *parent, unsigned char index) |
| 171 | { |
| 172 | unsigned int i; |
| 173 | void *p = NULL; |
| 174 | |
| 175 | assert(tree && parent); |
| 176 | assert(CLR_PTR_TYPE(parent->a[index]) == tree); |
| 177 | |
| 178 | for (i = 0; i < 16; i++) { |
| 179 | if (GET_PTR_TYPE(tree->a[i]) != PTR_TYPE_NULL) { |
| 180 | if (p) /* more than one entry */ |
| 181 | return -2; |
| 182 | p = tree->a[i]; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | if (p && (GET_PTR_TYPE(p) != PTR_TYPE_NOTE)) |
| 187 | return -2; |
| 188 | /* replace tree with p in parent[index] */ |
| 189 | parent->a[index] = p; |
| 190 | free(tree); |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | * To remove a leaf_node: |