fix: transplant with successor as a replace
When transplanting node with a successor, instead of redoing the links, just swap the value and delete „abused“ successor, which allows more straightforward rebalance. Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
b0b712b2f6
commit
966e1dd935
1 changed files with 4 additions and 10 deletions
|
@ -143,18 +143,12 @@ class RankedTree {
|
|||
this.transplant(node, node.left);
|
||||
} else {
|
||||
let successor = nodeMinimum(node.right);
|
||||
parent = successor.parent != node ? successor.parent : successor;
|
||||
|
||||
if (successor.parent != node) {
|
||||
parent = successor.right ? successor.right : successor.parent;
|
||||
this.transplant(successor, successor.right);
|
||||
successor.right = node.right;
|
||||
successor.right.parent = successor;
|
||||
}
|
||||
node.value = successor.value;
|
||||
successor.value = null;
|
||||
this.record();
|
||||
|
||||
this.transplant(node, successor);
|
||||
successor.left = node.left;
|
||||
node.left.parent = successor;
|
||||
return this.deleteNode(successor);
|
||||
}
|
||||
|
||||
this.record();
|
||||
|
|
Loading…
Reference in a new issue