{
MInterval root = (MInterval) p.Val;
root.Pop (from, to);
+ DumpPropNested ();
root.MergeAfterChange (from, to);
}
}
private void vacate_node (MInterval interval)
{
- M17N.DebugPrint ("vacate #{0} to #{1}", ID, interval.ID);
+ vacate_node (interval, null);
+ }
+
+ private void vacate_node (MInterval interval, MInterval stop)
+ {
+ if (interval != null)
+ M17N.DebugPrint ("vacate #{0} to #{1}\n", ID, interval.ID);
+ else
+ M17N.DebugPrint ("vacate #{0} to null\n", ID);
if (interval != null)
interval.Parent = Parent;
if (Parent == null)
int diff = Length;
if (interval != null)
diff -= interval.Length;
- for (MInterval i = Parent; i != null; i = i.Parent)
+ for (MInterval i = Parent; i != stop; i = i.Parent)
i.Length -= diff;
}
}
private static void merge_nodes (MInterval head, MInterval tail)
{
M17N.DebugPrint ("merging "); head.DumpOne (true, false);
- M17N.DebugPrint (" through "); tail.DumpOne (true, true);
+ M17N.DebugPrint (" through "); tail.DumpOne (true, false);
int from = head.From;
int to = tail.To;
for (root = head; root.To + head.RightLength < to;
root = root.Parent);
- M17N.DebugPrint ("common root is "); root.DumpOne (false, true);
+ M17N.DebugPrint (" common root is "); root.DumpOne (false, true);
if (from < root.From)
{
while (true)
{
- int len = prev.Length - prev.LeftLength;
-
M17N.DebugPrint ("merging "); prev.DumpOne (false, true);
+ prev.vacate_node (prev.Left, root);
+ if (prev == head)
+ break;
if (prev.Left != null)
- {
- prev.Left.Parent = prev.Parent;
- if (prev.Parent.Right == prev)
- 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;
- }
+ 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 = prev.Parent;
}
}
if (root.To < to)
while (true)
{
- int len = next.Length - next.RightLength;
-
M17N.DebugPrint ("merging "); next.DumpOne (false, true);
+ next.vacate_node (next.Right, root);
+ if (next == tail)
+ break;
if (next.Right != null)
- {
- next.Right.Parent = next.Parent;
- if (next.Parent.Left == next)
- 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;
- }
+ 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 = next.Parent;
}
}
}