From eb26069dc0a0d449e6a47a0ded8c17acd49abdac Mon Sep 17 00:00:00 2001 From: ntakahas Date: Fri, 12 Jun 2009 06:24:08 +0000 Subject: [PATCH] *** empty log message *** --- Makefile | 2 +- frontsensitive.cs | 14 +-- frontsticky.cs | 2 +- rearsensitive.cs | 14 +-- rearsticky.cs | 2 +- rf_.cs | 259 ----------------------------------------------------- sensitive.cs | 76 ++++++++++++---- 7 files changed, 80 insertions(+), 289 deletions(-) delete mode 100644 rf_.cs diff --git a/Makefile b/Makefile index 7ae3864..d4d6839 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CS=gmcs2 +CS=gmcs M17N_SRC = M17N.cs CORE_SRC = MSymbol.cs MPlist.cs MText.cs MDatabase.cs diff --git a/frontsensitive.cs b/frontsensitive.cs index 4ec15fe..84e12e8 100644 --- a/frontsensitive.cs +++ b/frontsensitive.cs @@ -30,9 +30,9 @@ public class Test for (i = from - 1; i >= 0 && valtable[i] == sym; i--) valtable[i] = null; } - if (to < LENGTH && valtable[to] != null) + if (to < LENGTH && valtable[to - 1] != null) { - sym = valtable[to]; + sym = valtable[to - 1]; for (i = to; i < LENGTH && valtable[i] == sym; i++) valtable[i] = null; } @@ -54,9 +54,9 @@ public class Test for (i = from - 1; i >= 0 && valtable[i] == sym; i--) valtable[i] = null; } - if (to < LENGTH && valtable[to] != null) + if (to < LENGTH && valtable[to - 1] != null) { - sym = valtable[to]; + sym = valtable[to - 1]; for (i = to; i < LENGTH && valtable[i] == sym; i++) valtable[i] = null; } @@ -98,6 +98,8 @@ public class Test // delete for (i = to; i < LENGTH; i++) valtable[i - l] = valtable[i]; + for (i = LENGTH - l; i < LENGTH; i++) + valtable[i] = null; // sensitivity for insertion if (from2 > 0 && valtable[from2] != null) @@ -132,7 +134,9 @@ public class Test if (valtable[i] != (MSymbol) val) { Console.WriteLine ("valtable[{0}] is {1}, GetProp returned {2}", - i, valtable[i], val); + i, + valtable[i] == null ? MSymbol.nil : valtable[i], + val == null ? MSymbol.nil : val); return false; } } diff --git a/frontsticky.cs b/frontsticky.cs index f3b1d3c..0507342 100644 --- a/frontsticky.cs +++ b/frontsticky.cs @@ -8,7 +8,7 @@ public class Test const int LENGTH = 10; const int DEPTH = 10; static MText mt = new MText ("0123456789"); - static MSymbol key = MSymbol.PropertyKey ("_f_", MProperty.Flags.FrontSticky); + static MSymbol key = MSymbol.PropertyKey ("fst", MProperty.Flags.FrontSticky); static MSymbol val0 = MSymbol.Of ("0"); static MSymbol val1 = MSymbol.Of ("1"); static MSymbol val2 = MSymbol.Of ("2"); diff --git a/rearsensitive.cs b/rearsensitive.cs index 9fa52bf..ddd06e0 100644 --- a/rearsensitive.cs +++ b/rearsensitive.cs @@ -24,9 +24,9 @@ public class Test int i; MSymbol sym; - if (from > 0 && valtable[from - 1] != null) + if (from > 0 && valtable[from] != null) { - sym = valtable[from - 1]; + sym = valtable[from]; for (i = from - 1; i >= 0 && valtable[i] == sym; i--) valtable[i] = null; } @@ -48,9 +48,9 @@ public class Test int i; MSymbol sym; - if (from > 0 && valtable[from - 1] != null) + if (from > 0 && valtable[from] != null) { - sym = valtable[from - 1]; + sym = valtable[from]; for (i = from - 1; i >= 0 && valtable[i] == sym; i--) valtable[i] = null; } @@ -98,6 +98,8 @@ public class Test // delete for (i = to; i < LENGTH; i++) valtable[i - l] = valtable[i]; + for (i = LENGTH - l; i < LENGTH; i++) + valtable[i] = null; // sensitivity for insertion if (from2 > 0 && valtable[from2 - 1] != null) @@ -132,7 +134,9 @@ public class Test if (valtable[i] != (MSymbol) val) { Console.WriteLine ("valtable[{0}] is {1}, GetProp returned {2}", - i, valtable[i], val); + i, + valtable[i] == null ? MSymbol.nil : valtable[i], + val == null ? MSymbol.nil : val); return false; } } diff --git a/rearsticky.cs b/rearsticky.cs index 7cace8b..deea91c 100644 --- a/rearsticky.cs +++ b/rearsticky.cs @@ -8,7 +8,7 @@ public class Test const int LENGTH = 10; const int DEPTH = 10; static MText mt = new MText ("0123456789"); - static MSymbol key = MSymbol.PropertyKey ("r__", MProperty.Flags.RearSticky); + static MSymbol key = MSymbol.PropertyKey ("rst", MProperty.Flags.RearSticky); static MSymbol val0 = MSymbol.Of ("0"); static MSymbol val1 = MSymbol.Of ("1"); static MSymbol val2 = MSymbol.Of ("2"); diff --git a/rf_.cs b/rf_.cs deleted file mode 100644 index fb2fcd9..0000000 --- a/rf_.cs +++ /dev/null @@ -1,259 +0,0 @@ -using System; -using System.Collections.Generic; -using M17N; -using M17N.Core; - -public class Test -{ - const int LENGTH = 10; - const int DEPTH = 10; - static MText mt = new MText ("0123456789"); - static MSymbol key = MSymbol.PropertyKey ("rf_", - MProperty.Flags.FrontSticky - | MProperty.Flags.RearSticky); - static MSymbol val0 = MSymbol.Of ("0"); - static MSymbol val1 = MSymbol.Of ("1"); - static MSymbol val2 = MSymbol.Of ("2"); - static MProperty prop0 = new MProperty (key, val0); - static MProperty prop1 = new MProperty (key, val1); - static MProperty prop2 = new MProperty (key, val2); - - static int[] nvals = new int[LENGTH]; - static MSymbol[,] valtable = new MSymbol[LENGTH, DEPTH + 1]; - - static void TestPushProp (int from, int to, MProperty prop) - { - for (int i = from; i < to; i++) - if (nvals[i] == DEPTH) - return; - - for (int i = from; i < to; i++) - { - valtable[i, nvals[i]] = (MSymbol) prop.Val; - nvals[i]++; - } - Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop); - - mt.PushProp (from, to, prop); - } - - static void TestPopProp (int from, int to, MSymbol key) - { - for (int i = from; i < to; i++) - if (nvals[i] > 0) - { - valtable[i, nvals[i] - 1] = null; - nvals[i]--; - } - Console.WriteLine ("from {0}, to {1}, pop.\n", from, to); - - mt.PopProp (from, to, key); - } - - static void TestDelIns (int from, int to, int from2) - { - int i, j, l = to - from; - int[] nvals2 = new int[LENGTH]; - MSymbol[,] valtable2 = new MSymbol[LENGTH, DEPTH + 1]; - - // copy - for (i = from; i < to; i++) - { - nvals2[i - from] = nvals[i]; - for (j = 0; j < nvals[i]; j++) - valtable2[i - from, j] = valtable[i, j]; - } - - // delete - for (i = to; i < LENGTH; i++) - { - nvals[i - l] = nvals[i]; - for (j = 0; j < nvals[i]; j++) - valtable[i - l, j] = valtable[i, j]; - } - - // move - for (i = LENGTH - 1; i >= from2 + l; i--) - { - nvals[i] = nvals[i - l]; - for (j = 0; j < nvals[i]; j++) - valtable[i, j] = valtable[i - l, j]; - } - - // insert - if (from2 > 0 && nvals[from2 - 1] > 0) - for (i = from2; i < from2 + l; i++) - { - nvals[i] = nvals[from2 - 1]; - for (j = 0; j < nvals[from2 - 1]; j++) - valtable[i, j] = valtable[from2 - 1, j]; - } - else if (from2 + l < LENGTH && nvals[from2 + l] > 0) - for (i = from2; i < from2 + l; i++) - { - nvals[i] = nvals[from2 + l]; - for (j = 0; j < nvals[from2 + l]; j++) - valtable[i, j] = valtable[from2 + l, j]; - } - else - for (i = from2; i < from2 + l; i++) - { - nvals[i] = nvals2[i - from2]; - for (j = 0; j < nvals2[i - from2]; j++) - valtable[i, j] = valtable2[i - from2, j]; - } - Console.WriteLine ("from {0}, to {1}, moveto {2}.\n", from, to, from2); - - MText mt2 = mt.Dup (); - mt.Del (from, to); - mt.Ins (from2, mt2, from, to); - } - - static bool Compare () - { - for (int i = 0; i < LENGTH; i++) - { - MProperty[] array; - object val = mt.GetProp (i, key, out array); - - if (array == null) - { - if (nvals[i] != 0) - { - Console.WriteLine ("nvals[{0}] is {1}, array.Length is null.\n", - i, nvals[i]); - return false; - } - } - - else if (nvals[i] != array.Length) - { - Console.WriteLine ("nvals[{0}] is {1}, array.Length is {2}.\n", - i, nvals[i], array.Length); - return false; - } - - else - { - for (int j = 0; j < nvals[i]; j++) - if (valtable[i, nvals[i] - 1 - j] != (MSymbol) array[j].Val) - { - Console.WriteLine ("valtable[{0}, {1}] is {2}, array[{1}] is {3}.\n", - i, j, valtable[i, j], array[j]); - return false; - } - } - - if (val == null) - { - if (nvals[i] != 0) - { - Console.WriteLine ("GetProp returned null for index {0}.\n", - i); - return false; - } - } - - else - { - if (nvals[i] == 0) - { - Console.WriteLine ("GetProp returned {0} for index {1}.\n", - val, i); - return false; - } - - else if (valtable[i, nvals[i] - 1] == null) - { - Console.WriteLine ("GetProp returned {0} for index {1}.\n", - val, i); - return false; - } - - else if ((MSymbol) val != valtable[i, nvals[i] - 1]) - { - Console.WriteLine ("GetProp returned {0} for index {1}.\n", - val, i); - return false; - } - } - } - return true; - } - - static void Dump () - { - for (int i = 0; i < LENGTH; i++) - { - Console.Write (i + " "); - for (int j = nvals[i] - 1; j >= 0; j--) - Console.Write (valtable[i,j] + " "); - Console.WriteLine (":"); - } - Console.WriteLine (""); - } - - public static void Main (string[] args) - { - Random r = new Random (int.Parse (args[0])); - int check = (args.Length > 1 ? int.Parse (args[1]) : 0xFFFFFFF); - - for (int loop = 0; loop < 1000000; loop++) - { - Console.WriteLine ("--- loop = {0} ---\n", loop); - if (loop >= check) - { - mt.DumpPropNested (); - Dump (); - M17n.debug = true; - } - - int from = r.Next (LENGTH); - int to = r.Next (LENGTH + 1); - if (from > to) - { - int tmp = from; - from = to; - to = tmp; - } - - MProperty prop; - switch (r.Next (3)) - { - case 0: - prop = prop0; - break; - case 1: - prop = prop1; - break; - default: - prop = prop2; - break; - } - - switch (r.Next (3)) - { - case 0: - TestPushProp (from, to, prop); - break; - case 1: - TestPopProp (from, to, key); - break; - case 2: - TestDelIns (from, to, r.Next (LENGTH - (to - from) + 1)); - break; - } - - if (M17n.debug) - mt.DumpPropNested (); - - if (Compare () == false) - { - Console.WriteLine (""); - Dump (); - Console.WriteLine ("Failed."); - return; - } - } - } -} diff --git a/sensitive.cs b/sensitive.cs index 9617de9..95e3900 100644 --- a/sensitive.cs +++ b/sensitive.cs @@ -8,7 +8,7 @@ public class Test const int LENGTH = 10; const int DEPTH = 10; static MText mt = new MText ("0123456789"); - static MSymbol key = MSymbol.PropertyKey ("__s", + static MSymbol key = MSymbol.PropertyKey ("se", MProperty.Flags.Sensitive); static MSymbol val0 = MSymbol.Of ("0"); static MSymbol val1 = MSymbol.Of ("1"); @@ -22,11 +22,20 @@ public class Test static void TestPushProp (int from, int to, MProperty prop) { int i; + MSymbol sym; - for (i = from - 1; i >= 0 && valtable[i] == valtable[from]; i--) - valtable[i] = null; - for (i = to; i < LENGTH && valtable[i] == valtable[to - 1]; i++) - valtable[i] = null; + 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) + { + sym = valtable[to - 1]; + for (i = to; i < LENGTH && valtable[i] == sym; i++) + valtable[i] = null; + } for (i = from; i < to; i++) valtable[i] = (MSymbol) prop.Val; Console.WriteLine ("from {0}, to {1}, push {2}.\n", from, to, prop.Val); @@ -37,11 +46,20 @@ public class Test static void TestPopProp (int from, int to, MSymbol key) { int i; + MSymbol sym; - for (i = from - 1; i >= 0 && valtable[i] == valtable[from]; i--) - valtable[i] = null; - for (i = to; i < LENGTH && valtable[i] == valtable[to]; i++) - valtable[i] = null; + 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) + { + sym = valtable[to - 1]; + for (i = to; i < LENGTH && valtable[i] == sym; i++) + valtable[i] = null; + } for (i = from; i < to; i++) valtable[i] = null; Console.WriteLine ("from {0}, to {1}, pop.\n", from, to); @@ -53,28 +71,50 @@ public class Test { int i, l = to - from; MSymbol[] valtable2 = new MSymbol[LENGTH]; + MSymbol sym; + + // sensitivity for deletion + if (from > 0 && valtable[from - 1] == valtable[from] + && valtable[from] != null) + { + 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; + } + if (to < LENGTH && valtable[to - 1] == valtable[to] + && valtable[to] != null) + { + 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; + } // copy for (i = from; i < to; i++) valtable2[i - from] = valtable[i]; // delete - for (i = from - 1; i >= 0 && valtable[i] == valtable[from]; i--) - valtable[i] = null; - for (i = to; i < LENGTH && valtable[i] == valtable[to - 1]; i++) - valtable[i] = null; for (i = to; i < LENGTH; i++) valtable[i - l] = valtable[i]; + for (i = LENGTH - l; i < LENGTH; i++) + valtable[i] = null; - // move - MSymbol sym = valtable[from2]; - if (from2 > 0 && valtable[from2 - 1] == sym) + // sensitivity for insertion + if (from2 > 0 && valtable[from2 - 1] == valtable[from2] + && valtable[from2] != null) { + 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; } + + // move for (i = LENGTH - 1; i >= from2 + l; i--) valtable[i] = valtable[i - l]; @@ -97,7 +137,9 @@ public class Test if (valtable[i] != (MSymbol) val) { Console.WriteLine ("valtable[{0}] is {1}, GetProp returned {2}", - i, valtable[i], val); + i, + valtable[i] == null ? MSymbol.nil : valtable[i], + val == null ? MSymbol.nil : val); return false; } } -- 1.7.10.4