diff --git a/crates/rbtree/src/lib.rs b/crates/rbtree/src/lib.rs index 8183fdd..5212ec5 100644 --- a/crates/rbtree/src/lib.rs +++ b/crates/rbtree/src/lib.rs @@ -139,6 +139,7 @@ impl> RBTree { } } else { self.root = Some(y); + self.store.get_mut(y).unwrap().set_parent(None); } } @@ -176,6 +177,7 @@ impl> RBTree { } } else { self.root = Some(y); + self.store.get_mut(y).unwrap().set_parent(None); } } @@ -380,6 +382,12 @@ impl> RBTree { self.store.get_mut(parent).unwrap().set_right(x); } + let color = self.store.get(y).unwrap().color(); + // If Y is Z's successor, move Y's data into Z (or move Z's meta into Y). + if y != z { + self.copy_meta_to(z, y); + } + if let Some(x_id) = x { // If X was red, color it black. Since it replaces a black node, the // black-height of the subtree is preserved. @@ -390,12 +398,6 @@ impl> RBTree { return; } - let color = self.store.get(y).unwrap().color(); - // If Y is Z's successor, move Y's data into Z (or move Z's meta into Y). - if y != z { - self.copy_meta_to(z, y); - } - // If X is None and Y was black, then a black node was removed, and the tree // needs to be rebalanced. if !color {