From: ntakahas Date: Tue, 30 Jun 2009 08:05:40 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=1f42af6e0c54492caddcaa5a6c1611257e39c608;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/sensitive.cs b/sensitive.cs index 95e3900..4597656 100644 --- a/sensitive.cs +++ b/sensitive.cs @@ -17,111 +17,110 @@ public class Test static MProperty prop1 = new MProperty (key, val1); static MProperty prop2 = new MProperty (key, val2); - static MSymbol[] valtable = new MSymbol[LENGTH]; + // Each property is identified by its beginning point. + // The character at position i has the property that begins at prop[i]. + // If the character has no property, prop[i] == -1. + static int[] prop = new int[LENGTH]; - static void TestPushProp (int from, int to, MProperty prop) + // The property beginning at position i ends at position end[i]. + // If no property begins at position i, end[i] is undefined. + static int[] end = new int[LENGTH]; + + // The property beginning at position i has value value[i]. + // If no property begings at positoin i, value[i] is undefined. + static MSymbol[] value = new MSymbol[LENGTH]; + + static void TestPushProp (int from, int to, MProperty newprop) { - int i; - MSymbol sym; + Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, newprop.Val); - if (from > 0 && valtable[from] != null) - { - sym = valtable[from]; - for (i = from - 1; i >= 0 && valtable[i] == sym; i--) - valtable[i] = null; - } - if (to < LENGTH && valtable[to - 1] != null) + int i, n; + + if (from > 0 && prop[from - 1] == prop[from] && prop[from] != -1) + for (i = prop[from]; i < from; i++) + prop[i] = -1; + if (to < LENGTH && prop[to - 1] == prop[to] && prop[to] != -1) { - sym = valtable[to - 1]; - for (i = to; i < LENGTH && valtable[i] == sym; i++) - valtable[i] = null; + n = end[prop[to]]; + for (i = to; i < n; i++) + prop[i] = -1; } for (i = from; i < to; i++) - valtable[i] = (MSymbol) prop.Val; - Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop.Val); + prop[i] = from; + end[from] = to; + value[from] = (MSymbol) newprop.Val; - mt.PushProp (from, to, prop); + mt.PushProp (from, to, newprop); } static void TestPopProp (int from, int to, MSymbol key) { - int i; - MSymbol sym; + Console.WriteLine ("from {0}, to {1}, pop.\n", from, to); - if (from > 0 && valtable[from] != null) - { - sym = valtable[from]; - for (i = from - 1; i >= 0 && valtable[i] == sym; i--) - valtable[i] = null; - } - if (to < LENGTH && valtable[to - 1] != null) + int i, n; + + if (from > 0 && prop[from - 1] == prop[from] && prop[from] != -1) + for (i = prop[from]; i < from - 1; i++) + prop[i] = -1; + + if (to < LENGTH && prop[to - 1] == prop[to] && prop[to] != -1) { - sym = valtable[to - 1]; - for (i = to; i < LENGTH && valtable[i] == sym; i++) - valtable[i] = null; + n = end[prop[to]]; + for (i = to; i < n; i++) + prop[i] = -1; } + for (i = from; i < to; i++) - valtable[i] = null; - Console.WriteLine ("from {0}, to {1}, pop.\n", from, to); + prop[i] = -1; mt.PopProp (from, to, key); } static void TestDelIns (int from, int to, int from2) { - int i, l = to - from; - MSymbol[] valtable2 = new MSymbol[LENGTH]; - MSymbol sym; + Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2); + + int i, n, l = to - from; + int[] prop2 = new int[LENGTH]; // sensitivity for deletion - if (from > 0 && valtable[from - 1] == valtable[from] - && valtable[from] != null) + if (from > 0 && prop[from - 1] == prop[from] && prop[from] != -1) { - sym = valtable[from]; - for (i = from - 1; i >= 0 && valtable[i] == sym; i--) - valtable[i] = null; - for (i = from; i < LENGTH && valtable[i] == sym; i++) - valtable[i] = null; + n = end[prop[from]]; + for (i = prop[from]; i < n; i++) + prop[i] = -1; } - if (to < LENGTH && valtable[to - 1] == valtable[to] - && valtable[to] != null) + + if (to < LENGTH && prop[to - 1] == prop[to] && prop[to] != -1) { - sym = valtable[to - 1]; - for (i = to - 1; i >= 0 && valtable[i] == sym; i--) - valtable[i] = null; - for (i = to; i < LENGTH && valtable[i] == sym; i++) - valtable[i] = null; + n = end[prop[to]]; + for (i = prop[to]; i < n; i++) + prop[i] = -1; } // copy for (i = from; i < to; i++) - valtable2[i - from] = valtable[i]; + prop2[i - from] = prop[i]; // delete for (i = to; i < LENGTH; i++) - valtable[i - l] = valtable[i]; - for (i = LENGTH - l; i < LENGTH; i++) - valtable[i] = null; + prop[i - l] = prop[i]; // sensitivity for insertion - if (from2 > 0 && valtable[from2 - 1] == valtable[from2] - && valtable[from2] != null) + if (from2 > 0 && prop[from2 - 1] == prop[from2] && prop[from2] != -1) { - sym = valtable[from2]; - for (i = from2 - 1; i >= 0 && valtable[i] == sym; i--) - valtable[i] = null; - for (i = from2; i < LENGTH && valtable[i] == sym; i++) - valtable[i] = null; + n = end[prop[from2]]; + for (i = prop[from2]; i < n; i++) + prop[i] = -1; } // move for (i = LENGTH - 1; i >= from2 + l; i--) - valtable[i] = valtable[i - l]; + prop[i] = prop[i - l]; // insert for (i = from2; i < from2 + l; i++) - valtable[i] = valtable2[i - from2]; - Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2); + prop[i] = prop2[i - from2]; MText mt2 = mt.Dup (); mt.Del (from, to); @@ -134,11 +133,19 @@ public class Test { object val = mt.GetProp (i, key); - if (valtable[i] != (MSymbol) val) + if (prop[i] == -1 && (MSymbol) val != null) + { + Console.WriteLine ("value[{0}] is nil, GetProp returned {1}", + i, + val == null ? MSymbol.nil : val); + return false; + } + + if (prop[i] != -1 && (value[prop[i]] != (MSymbol) val)) { - Console.WriteLine ("valtable[{0}] is {1}, GetProp returned {2}", + Console.WriteLine ("value[{0}] is {1}, GetProp returned {2}", i, - valtable[i] == null ? MSymbol.nil : valtable[i], + value[prop[i]] == null ? MSymbol.nil : value[prop[i]], val == null ? MSymbol.nil : val); return false; } @@ -149,7 +156,23 @@ public class Test static void Dump () { for (int i = 0; i < LENGTH; i++) - Console.WriteLine ("{0} {1} :", i, valtable[i]); + Console.Write ("{0} ", i); + Console.WriteLine ("\n-------------------"); + + if (prop[0] == -1) + Console.Write (" "); + else + Console.Write ("{0}", value[prop[0]]); + + for (int i = 1; i < LENGTH; i++) + { + if (prop[i] == -1) + Console.Write (" "); + else if (prop[i - 1] == prop[i]) + Console.Write ("< "); + else + Console.Write ("{0} ", value[prop[i]]); + } } public static void Main (string[] args) @@ -157,6 +180,10 @@ public class Test Random r = new Random (int.Parse (args[0])); int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF); + for (int i = 0; i < LENGTH; i++) + prop[i] = end[i] = -1; + + for (int loop = 0; loop < 1000000; loop++) { int from, to;