-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
The call to RecalculateMaxEnd occurs in a loop and goes up the tree, but RecalculateMaxEnd also does this. It seems that the extra while loop is redundant.
while (node.Parent != Sentinel) {
node = node.Parent;
node.RecalculateMaxEnd();
}
More context below.
private void RemoveNode(IntervalNode<T> node)
{
if (node == Sentinel) {
return;
}
IntervalNode<T> temp = node;
if (node.Right != Sentinel && node.Left != Sentinel) {
// Trick when deleting node with both children, switch it with closest in order node
// swap values and delete the bottom node converting it to other cases
temp = node.GetSuccessor();
node.Interval = temp.Interval;
node.RecalculateMaxEnd();
while (node.Parent != Sentinel) {
node = node.Parent;
node.RecalculateMaxEnd();
}
}
node = temp;
temp = node.Left != Sentinel ? node.Left : node.Right;
// we will replace node with temp and delete node
temp.Parent = node.Parent;
if (node.IsRoot) {
Root = temp; // Set new root
} else {
// Reattach node to parent
if (node.ParentDirection == NodeDirection.RIGHT) {
node.Parent.Left = temp;
} else {
node.Parent.Right = temp;
}
IntervalNode<T> maxAux = node.Parent;
maxAux.RecalculateMaxEnd();
while (maxAux.Parent != Sentinel) {
maxAux = maxAux.Parent;
maxAux.RecalculateMaxEnd();
}
}
if (node.Color == NodeColor.BLACK) {
RenewConstraintsAfterDelete(temp);
}
}
Metadata
Metadata
Assignees
Labels
No labels