Browse Source

Fixed problem where the root was allowed to be red

tree_alloc
Cameron Weinfurt 1 year ago
parent
commit
b771400238
  1. 22
      tree_alloc.c

22
tree_alloc.c

@ -322,7 +322,15 @@ void remove_node(TreeAlloc **root_ptr, TreeAlloc *node) {
node->left->parent = tmp;
}
if (do_repair && replace && replace->parent != NULL) {
if (replace && replace->parent == NULL) {
#ifdef DEBUG
printf("=== PRE-REMOVE-FIXUP ===\n");
printf("===== CURRENT TREE =====\n");
debug_print_tree(0, *root_ptr);
printf("===== END OF TREES =====\n");
#endif
replace->color = COLOR_BLACK;
} else if (do_repair && replace) {
#ifdef DEBUG
printf("=== PRE-REMOVE-FIXUP ===\n");
printf("===== CURRENT TREE =====\n");
@ -331,6 +339,12 @@ void remove_node(TreeAlloc **root_ptr, TreeAlloc *node) {
#endif
repair_after_remove(root_ptr, replace);
}
#ifdef DEBUG
printf("=== POST-REMOVE ===\n");
printf("===== CURRENT TREE =====\n");
debug_print_tree(0, *root_ptr);
printf("===== END OF TREES =====\n");
#endif
}
@ -345,6 +359,12 @@ void insert_singleton(TreeAlloc **root_ptr, TreeAlloc *to_insert) {
*root_ptr = to_insert;
to_insert->parent = NULL;
to_insert->color = COLOR_BLACK;
#ifdef DEBUG
printf("= POST-INSERT-SINGLETON =\n");
printf("===== CURRENT TREE =====\n");
debug_print_tree(0, *root_ptr);
printf("===== END OF TREES =====\n");
#endif
}
void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after) {

Loading…
Cancel
Save