From: handa Date: Fri, 24 Apr 2009 06:49:06 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=1ada025318cad407c29aed097dcb6603e6e41b7a;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/MText.cs b/MText.cs index 98cb0c5..5d8fb1b 100644 --- a/MText.cs +++ b/MText.cs @@ -260,20 +260,23 @@ namespace M17N.Core sb.Insert (pos_idx, mt2.sb.ToString (from_idx, to_idx - from_idx)); nchars += to - from; - foreach (MPlist plist in mt2.intervals) - if (intervals.Find (plist.Key) == null) - intervals.Push (plist.Key, new MInterval (plist.Key, this)); foreach (MPlist plist in intervals) { MPlist p = mt2.intervals.Find (plist.Key); - MInterval interval; + MInterval i; if (p == null) - interval = new MInterval (plist.Key, this, to - from); + i = new MInterval (plist.Key, this, to - from); else - interval = ((MInterval) p.Val).Copy (from, to); - ((MInterval) plist.Val).Insert (pos, interval); + i = ((MInterval) p.Val).Copy (this, from, to); + ((MInterval) plist.Val).Insert (pos, i); } + foreach (MPlist plist in mt2.intervals) + if (intervals.Find (plist.Key) == null) + { + MInterval i = (((MInterval) plist.Val).Copy (this, from, to)); + intervals.Push (plist.Key, i); + } } private void insert (int pos, int c) @@ -334,7 +337,7 @@ namespace M17N.Core MText mt = new MText (sb.ToString ()); foreach (MPlist p in intervals) - mt.intervals.Add (p.Key, ((MInterval) p.Val).Copy (0, Length)); + mt.intervals.Add (p.Key, ((MInterval) p.Val).Copy (mt, 0, Length)); return mt; } @@ -375,6 +378,8 @@ namespace M17N.Core ((MInterval) plist.Val).Delete (from, to); else intervals = new MPlist (); + if (M17N.debug) + DumpPropNested (); return this; } @@ -483,6 +488,7 @@ namespace M17N.Core public void DumpPropNested () { + Console.WriteLine ("total length = {0}", Length); foreach (MPlist p in intervals) ((MInterval) p.Val).DumpNested (true); } @@ -598,9 +604,9 @@ namespace M17N.Core private MInterval LeftMost { get { + update_from_to (); if (Left == null) return this; - Left.update_from_to (); return Left.LeftMost; } } @@ -608,9 +614,9 @@ namespace M17N.Core private MInterval RightMost { get { + update_from_to (); if (Right == null) return this; - Right.update_from_to (); return Right.RightMost; } } @@ -626,8 +632,7 @@ namespace M17N.Core { MInterval child = this; for (i = Parent; i != null && i.Left == child; - child = i, i = i.Parent) - i.update_from_to (); + child = i, i = i.Parent); } return i; } @@ -644,8 +649,7 @@ namespace M17N.Core { MInterval child = this; for (i = Parent; i != null && i.Right == child; - child = i, i = i.Parent) - i.update_from_to (); + child = i, i = i.Parent); } return i; } @@ -770,7 +774,7 @@ namespace M17N.Core return i; } - public MInterval Copy (int start, int end) + public MInterval Copy (MText mt, int start, int end) { MInterval copy, left_copy = null, right_copy = null; @@ -779,17 +783,18 @@ namespace M17N.Core if (start < From) { if (end <= From) - return Left.Copy (start, end); - left_copy = Left.Copy (start, From); + return Left.Copy (mt, start, end); + left_copy = Left.Copy (mt, start, From); } if (end > To) { if (start >= To) - return Right.Copy (start, end); - right_copy = Right.Copy (To, end); + return Right.Copy (mt, start, end); + right_copy = Right.Copy (mt, To, end); } copy = new MInterval (Key, null, end - start, Stack); + copy.mtext = mt; remove_properties (MTextProperty.Flag.Sensitive); if (left_copy != null) { @@ -917,7 +922,7 @@ namespace M17N.Core { if (Parent != null) { - int len = Length - RightLength; + int len = Length - LeftLength; for (MInterval i = Parent; i != null; i = i.Parent) i.Length -= len; @@ -972,8 +977,11 @@ namespace M17N.Core } } + if (len == 0) + return interval; Length += len; To += len; + M17N.DebugPrint ("grafted {0} in ", len); DumpOne (false, true); for (MInterval prev = this, ii = this.Parent; ii != null; prev = ii, ii = ii.Parent) { diff --git a/textprop.cs b/textprop.cs index aed4f04..3a020de 100644 --- a/textprop.cs +++ b/textprop.cs @@ -195,12 +195,12 @@ public class Test public static void Main (string[] args) { Random r = new Random (int.Parse (args[0])); - int check = (args.Length > 1 ? int.Parse (args[1]) : -1); + int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF); - for (int loop = 0; loop < 30; loop++) + for (int loop = 0; loop < 100000; loop++) { Console.WriteLine ("--- loop = {0} ---\n", loop); - if (loop == check) + if (loop >= check) { mt.DumpPropNested (); Dump (); @@ -271,6 +271,5 @@ public class Test return; } } - } }