fix rbtree
This commit is contained in:
parent
3182f4e7f0
commit
b407abb094
|
|
@ -139,6 +139,7 @@ impl<N: Node, S: NodeStore<N>> RBTree<N, S> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.root = Some(y);
|
self.root = Some(y);
|
||||||
|
self.store.get_mut(y).unwrap().set_parent(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,6 +177,7 @@ impl<N: Node, S: NodeStore<N>> RBTree<N, S> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.root = Some(y);
|
self.root = Some(y);
|
||||||
|
self.store.get_mut(y).unwrap().set_parent(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -380,6 +382,12 @@ impl<N: Node, S: NodeStore<N>> RBTree<N, S> {
|
||||||
self.store.get_mut(parent).unwrap().set_right(x);
|
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 let Some(x_id) = x {
|
||||||
// If X was red, color it black. Since it replaces a black node, the
|
// If X was red, color it black. Since it replaces a black node, the
|
||||||
// black-height of the subtree is preserved.
|
// black-height of the subtree is preserved.
|
||||||
|
|
@ -390,12 +398,6 @@ impl<N: Node, S: NodeStore<N>> RBTree<N, S> {
|
||||||
return;
|
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
|
// If X is None and Y was black, then a black node was removed, and the tree
|
||||||
// needs to be rebalanced.
|
// needs to be rebalanced.
|
||||||
if !color {
|
if !color {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue