if (from < root.From)
{
MInterval prev = root.Prev;
- int deleting = root.From - from;
- int deleted = 0;
- while (deleted < deleting)
+ while (true)
{
int len = prev.Length - prev.LeftLength;
M17N.DebugPrint ("merging "); prev.DumpOne (false, true);
- deleted += len;
if (prev.Left != null)
{
prev.Left.Parent = prev.Parent;
prev.Parent.Right = prev.Left;
else
prev.Parent.Left = prev.Left;
+ for (MInterval i = prev.Parent; i != root; i = i.Parent)
+ i.Length -= len;
+ if (prev == head)
+ break;
prev = prev.Left.RightMost;
}
else
{
+ prev.Parent.Right = null;
+ for (MInterval i = prev.Parent; i != root; i = i.Parent)
+ i.Length -= len;
+ if (prev == head)
+ break;
prev = prev.Parent;
- prev.Right = null;
- prev.Length -= deleted;
}
}
- while (prev.Parent != root)
- {
- prev.Length -= deleted;
- prev = prev.Parent;
- }
}
if (root.To < to)
{
MInterval next = root.Next;
- int deleting = root.To - to;
- int deleted = 0;
- while (deleted < deleting)
+ while (true)
{
int len = next.Length - next.RightLength;
M17N.DebugPrint ("merging "); next.DumpOne (false, true);
- deleted += len;
if (next.Right != null)
{
next.Right.Parent = next.Parent;
next.Parent.Left = next.Right;
else
next.Parent.Right = next.Right;
+ for (MInterval i = next.Parent; i != root; i = i.Parent)
+ i.Length -= len;
+ if (next == tail)
+ break;
next = next.Right.LeftMost;
}
else
{
+ next.Parent.Left = null;
+ for (MInterval i = next.Parent; i != root; i = i.Parent)
+ i.Length -= len;
+ if (next == tail)
+ break;
next = next.Parent;
- next.Left = null;
- next.Length -= deleted;
}
}
- while (next.Parent != root)
- {
- next.Length -= deleted;
- next = next.Parent;
- }
}
}