From: ntakahas Date: Tue, 30 Jun 2009 11:01:03 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8dd681508a40553d93490da7ab57607648112b9;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/sensitive.cs b/sensitive.cs index 4597656..ed54fbc 100644 --- a/sensitive.cs +++ b/sensitive.cs @@ -5,9 +5,8 @@ using M17N.Core; public class Test { - const int LENGTH = 10; - const int DEPTH = 10; - static MText mt = new MText ("0123456789"); + const int LENGTH = 9; + static MText mt = new MText ("012345678"); static MSymbol key = MSymbol.PropertyKey ("se", MProperty.Flags.Sensitive); static MSymbol val0 = MSymbol.Of ("0"); @@ -37,8 +36,11 @@ public class Test int i, n; if (from > 0 && prop[from - 1] == prop[from] && prop[from] != -1) - for (i = prop[from]; i < from; i++) - prop[i] = -1; + { + n = end[prop[from]]; + for (i = prop[from]; i < n; i++) + prop[i] = -1; + } if (to < LENGTH && prop[to - 1] == prop[to] && prop[to] != -1) { n = end[prop[to]]; @@ -59,8 +61,9 @@ public class Test int i, n; + Console.WriteLine ("prop[from] = {0}", prop[from]); if (from > 0 && prop[from - 1] == prop[from] && prop[from] != -1) - for (i = prop[from]; i < from - 1; i++) + for (i = prop[from]; i < from; i++) prop[i] = -1; if (to < LENGTH && prop[to - 1] == prop[to] && prop[to] != -1) @@ -81,8 +84,10 @@ public class Test Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2); int i, n, l = to - from; - int[] prop2 = new int[LENGTH]; + int[] prop2 = new int[LENGTH], end2 = new int[LENGTH]; + MSymbol[] value2 = new MSymbol[LENGTH]; + DebugDump (0); // sensitivity for deletion if (from > 0 && prop[from - 1] == prop[from] && prop[from] != -1) { @@ -98,14 +103,35 @@ public class Test prop[i] = -1; } + DebugDump (1); // copy for (i = from; i < to; i++) - prop2[i - from] = prop[i]; + { + if (prop[i] != -1) + { + prop2[i - from] = prop[i] - from + from2; + end2[prop2[i - from]] = end[prop[i]] - from + from2; + value2[prop2[i - from]] = value[prop[i]]; + } + else + prop2[i - from] = -1; + } + DebugDump (2); // delete for (i = to; i < LENGTH; i++) - prop[i - l] = prop[i]; + { + if (prop[i] != -1) + { + prop[i - l] = prop[i] - l; + end[prop[i - l]] = end[prop[i]] - l; + value[prop[i - l]] = value[prop[i]]; + } + else + prop[i - l] = -1; + } + DebugDump (3); // sensitivity for insertion if (from2 > 0 && prop[from2 - 1] == prop[from2] && prop[from2] != -1) { @@ -114,13 +140,34 @@ public class Test prop[i] = -1; } + DebugDump (4); // move for (i = LENGTH - 1; i >= from2 + l; i--) - prop[i] = prop[i - l]; + { + if (prop[i - l] != -1) + { + prop[i] = prop[i - l] + l; + end[prop[i]] = end[prop[i - l]] + l; + value[prop[i]] = value[prop[i - l]]; + } + else + prop[i] = -1; + } + DebugDump (5); // insert for (i = from2; i < from2 + l; i++) - prop[i] = prop2[i - from2]; + { + if (prop2[i - from2] != -1) + { + prop[i] = prop2[i - from2]; + end[prop[i]] = end2[prop2[i - from2]]; + value[prop[i]] = value2[prop2[i - from2]]; + } + else + prop[i] = -1; + } + DebugDump (6); MText mt2 = mt.Dup (); mt.Del (from, to); @@ -155,14 +202,14 @@ public class Test static void Dump () { - for (int i = 0; i < LENGTH; i++) + for (int i = 0; i <= LENGTH; i++) Console.Write ("{0} ", i); Console.WriteLine ("\n-------------------"); if (prop[0] == -1) Console.Write (" "); else - Console.Write ("{0}", value[prop[0]]); + Console.Write ("{0} ", value[prop[0]]); for (int i = 1; i < LENGTH; i++) { @@ -173,6 +220,51 @@ public class Test else Console.Write ("{0} ", value[prop[i]]); } + Console.Write ("\n"); + } + + static void DebugDump (int n) + { + /* + int i; + + Console.Write ("\n#{0}\n ", n); + for (i = 0; i <= LENGTH; i++) + Console.Write ("{0} ", i); + Console.Write ("\n----------------------\nP "); + for (i = 0; i < LENGTH; i++) + { + if (prop[i] != -1) + Console.Write ("{0} ", prop[i]); + else + Console.Write (" "); + } + Console.Write ("\nE "); + if (prop[0] != -1) + Console.Write ("{0} ", end[0]); + else + Console.Write (" "); + for (i = 1; i < LENGTH; i++) + { + if (prop[i - 1] != prop[i] && prop[i] != -1) + Console.Write ("{0} ", end[i]); + else + Console.Write (" "); + } + Console.Write ("\nV "); + if (prop[0] != -1) + Console.Write ("{0} ", value[0]); + else + Console.Write (" "); + for (i = 1; i < LENGTH; i++) + { + if (prop[i - 1] != prop[i] && prop[i] != -1) + Console.Write ("{0} ", value[i]); + else + Console.Write (" "); + } + Console.Write ("\n"); + */ } public static void Main (string[] args) @@ -181,8 +273,7 @@ public class Test int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF); for (int i = 0; i < LENGTH; i++) - prop[i] = end[i] = -1; - + prop[i] = -1; for (int loop = 0; loop < 1000000; loop++) {