Browse Source

Actually called the fixup function in insert

tree_alloc
Thomas Johnson 1 year ago
parent
commit
ffc1382747
  1. 23
      tree_alloc.c

23
tree_alloc.c

@ -181,13 +181,6 @@ void rotate_right(TreeAlloc **root_ptr, TreeAlloc *ta) {
void repair_tree_after_insert(TreeAlloc **root_ptr, TreeAlloc *ta) {
TreeAlloc *parent = ta->parent;
#ifdef DEBUG
printf("=== PRE-INSERT-FIXUP ===\n");
printf("===== CURRENT TREE =====\n");
debug_print_tree(0, *root_ptr);
printf("===== END OF TREES =====\n");
#endif
if (ta == *root_ptr) {
ta->color = COLOR_BLACK;
} else if (IS_BLACK_NODE(parent)) {
@ -268,6 +261,8 @@ void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after)
after->right = to_insert;
to_insert->parent = after;
}
to_insert->color = COLOR_RED;
repair_tree_after_insert(root_ptr, to_insert);
#ifdef DEBUG
printf("== POST-INSERT-FIXUP ===\n");
printf("===== CURRENT TREE =====\n");
@ -296,6 +291,8 @@ void insert_left(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* before)
before->left = to_insert;
to_insert->parent = before;
}
to_insert->color = COLOR_RED;
repair_tree_after_insert(root_ptr, to_insert);
#ifdef DEBUG
printf("== POST-INSERT-FIXUP ===\n");
printf("===== CURRENT TREE =====\n");
@ -399,20 +396,8 @@ void remove_node(TreeAlloc **root_ptr, TreeAlloc *to_remove) {
to_remove->parent = to_remove->left = to_remove->right = 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");
debug_print_tree(0, *root_ptr);
printf("===== END OF TREES =====\n");
#endif
repair_after_remove(root_ptr, replace);
}
#ifdef DEBUG

Loading…
Cancel
Save