Browse Source

Actually called the fixup function in insert

Thomas Johnson 5 months ago
parent
commit
ffc1382747
1 changed files with 4 additions and 19 deletions
  1. 4
    19
      tree_alloc.c

+ 4
- 19
tree_alloc.c View File

@@ -181,13 +181,6 @@ void rotate_right(TreeAlloc **root_ptr, TreeAlloc *ta) {
181 181
 
182 182
 void repair_tree_after_insert(TreeAlloc **root_ptr, TreeAlloc *ta) {
183 183
 	TreeAlloc *parent = ta->parent;
184
-#ifdef DEBUG
185
-	printf("=== PRE-INSERT-FIXUP ===\n");
186
-	printf("===== CURRENT TREE =====\n");
187
-	debug_print_tree(0, *root_ptr);
188
-	printf("===== END OF TREES =====\n");
189
-#endif
190
-
191 184
 	if (ta == *root_ptr) {
192 185
 		ta->color = COLOR_BLACK;
193 186
 	} else if (IS_BLACK_NODE(parent)) {
@@ -268,6 +261,8 @@ void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after)
268 261
     after->right = to_insert;
269 262
     to_insert->parent = after;
270 263
   }
264
+  to_insert->color = COLOR_RED;
265
+  repair_tree_after_insert(root_ptr, to_insert);
271 266
 #ifdef DEBUG
272 267
 	printf("== POST-INSERT-FIXUP ===\n");
273 268
 	printf("===== CURRENT TREE =====\n");
@@ -296,6 +291,8 @@ void insert_left(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* before)
296 291
     before->left = to_insert;
297 292
     to_insert->parent = before;
298 293
   }
294
+  to_insert->color = COLOR_RED;
295
+  repair_tree_after_insert(root_ptr, to_insert);
299 296
 #ifdef DEBUG
300 297
 	printf("== POST-INSERT-FIXUP ===\n");
301 298
 	printf("===== CURRENT TREE =====\n");
@@ -399,20 +396,8 @@ void remove_node(TreeAlloc **root_ptr, TreeAlloc *to_remove) {
399 396
 	to_remove->parent = to_remove->left = to_remove->right = NULL;
400 397
 
401 398
 	if (replace && replace->parent == NULL) {
402
-#ifdef DEBUG
403
-		printf("=== PRE-REMOVE-FIXUP ===\n");
404
-		printf("===== CURRENT TREE =====\n");
405
-		debug_print_tree(0, *root_ptr);
406
-		printf("===== END OF TREES =====\n");
407
-#endif
408 399
 		replace->color = COLOR_BLACK;
409 400
 	} else if (do_repair && replace) {
410
-#ifdef DEBUG
411
-		printf("=== PRE-REMOVE-FIXUP ===\n");
412
-		printf("===== CURRENT TREE =====\n");
413
-		debug_print_tree(0, *root_ptr);
414
-		printf("===== END OF TREES =====\n");
415
-#endif
416 401
 		repair_after_remove(root_ptr, replace);
417 402
 	}
418 403
 #ifdef DEBUG

Loading…
Cancel
Save