From: handa Date: Mon, 5 Jan 2009 07:58:57 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=6ceb6b3d0cd44703121253955485d9d89b86db29;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/MPlist.cs b/MPlist.cs new file mode 100644 index 0000000..ffdea57 --- /dev/null +++ b/MPlist.cs @@ -0,0 +1,109 @@ +using System; +using M17N.Core; + +namespace M17N.Core +{ + public class MPlist + { + private MSymbol key; + private object val; + private MPlist next; + + public MPlist () + { + key = null; + val = null; + next = null; + } + + public bool tailp { get { return (object) key == null; } } + + public new string ToString () + { + string str = ""; + + for (MPlist p = this; ! p.tailp; p = p.next) + { + str += (p == this ? "(" : " ") + p.key.ToString () + ":"; + if (p.val is MSymbol) + str += ((MSymbol) p.val).ToString (); + else if (p.val is MPlist) + str += ((MPlist) p.val).ToString (); + } + return str + ")"; + } + + public object get (MSymbol key) + { + if ((object) key == null) + return null; + for (MPlist p = this; ! p.tailp; p = p.next) + if (p.key == key) + return p.val; + return null; + } + + public object put (MSymbol key, object val) + { + MPlist p; + + for (p = this; ! p.tailp; p = p.next) + if (p.key == key) + { + if (val != null) + p.val = val; + else + p.pop (); + return val; + } + if (val != null) + { + p.key = key; + p.val = val; + p.next = new MPlist (); + } + return val; + } + + public object push (MSymbol key, object val) + { + MPlist p = new MPlist (); + + p.key = this.key; + p.val = this.val; + p.next = this.next; + this.key = key; + this.val = val; + this.next = p; + + return val; + } + + public object pop () + { + if (tailp) + return null; + + object val = this.val; + + this.key = this.next.key; + this.val = this.next.val; + this.next = this.next.next; + return val; + } + + public object add (MSymbol key, object val) + { + MPlist p; + + for (p = this; ! p.tailp; p = p.next); + if (val != null) + { + p.key = key; + p.val = val; + p.next = new MPlist (); + } + return val; + } + } +} diff --git a/MSymbol.cs b/MSymbol.cs index 06e5370..bc67b1b 100644 --- a/MSymbol.cs +++ b/MSymbol.cs @@ -1,147 +1,22 @@ using System; +using System.Collections; using M17N.Core; namespace M17N.Core { - public class MPlist - { - private MSymbol key; - private object val; - private MPlist next; - - public MPlist () - { - key = null; - val = null; - next = null; - } - - public bool tailp { get { return (object) key == null; } } - - public new string ToString () - { - string str = ""; - - for (MPlist p = this; ! p.tailp; p = p.next) - { - str += (p == this ? "(" : " ") + p.key.ToString () + ":"; - if (p.val is MSymbol) - str += ((MSymbol) p.val).ToString (); - else if (p.val is MPlist) - str += ((MPlist) p.val).ToString (); - } - return str + ")"; - } - - public object get (MSymbol key) - { - if ((object) key == null) - return null; - for (MPlist p = this; ! p.tailp; p = p.next) - if (p.key == key) - return p.val; - return null; - } - - public object put (MSymbol key, object val) - { - MPlist p; - - for (p = this; ! p.tailp; p = p.next) - if (p.key == key) - { - if (val != null) - p.val = val; - else - p.pop (); - return val; - } - if (val != null) - { - p.key = key; - p.val = val; - p.next = new MPlist (); - } - return val; - } - - public object push (MSymbol key, object val) - { - MPlist p = new MPlist (); - - p.key = this.key; - p.val = this.val; - p.next = this.next; - this.key = key; - this.val = val; - this.next = p; - - return val; - } - - public object pop () - { - if (tailp) - return null; - - object val = this.val; - - this.key = this.next.key; - this.val = this.next.val; - this.next = this.next.next; - return val; - } - - public object add (MSymbol key, object val) - { - MPlist p; - - for (p = this; ! p.tailp; p = p.next); - if (val != null) - { - p.key = key; - p.val = val; - p.next = new MPlist (); - } - return val; - } - } - public class MSymbol { + static private Hashtable pool = new Hashtable (); + internal class MSymbolData { public string name; + public Object value; public MPlist plist; - public MSymbolData next; - public MSymbolData (string name, MSymbolData next) + public MSymbolData (string name) { this.name = name; - this.next = next; - } - } - - static internal class MSymbolPool - { - const int MSYMBOL_POOL_SIZE = 1024; - static MSymbolData[] pool = new MSymbolData[MSYMBOL_POOL_SIZE]; - static int[] used = new int[MSYMBOL_POOL_SIZE]; - - static public MSymbolData get_data (string name) - { - MSymbolData data; - - if (used[0] > 0) - { - data = pool[0]; - for (int i = 0; i < used[0]; i++, data = data.next) - if (data.name == name) - return data; - } - pool[0] = data = new MSymbolData (name, pool[0]); - used[0]++; - return data; } } @@ -152,14 +27,26 @@ namespace M17N.Core public MSymbol (string name) { - data = MSymbolPool.get_data (name); + if (! pool.ContainsKey (name)) + { + data = new MSymbolData (name); + pool.Add (name, data); + } + else + data = (MSymbolData) pool[name]; } - public new string ToString () { return data.name; } + public override string ToString () { return data.name; } - public new bool Equals (object sym) { return ((object) this == sym); } + public override bool Equals (Object sym) + { + return (this.data == ((MSymbol) sym).data); + } - public new int GetHashCode () { return 0; } + public override int GetHashCode () + { + return (data.name.GetHashCode ()); + } public static bool operator== (MSymbol sym1, MSymbol sym2) { diff --git a/Makefile b/Makefile index 77316fa..959f128 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -CORE_SRC = MSymbol.cs MText.cs +CORE_SRC = MSymbol.cs MPlist.cs MText.cs temp.cs -all: M17N.exe +all: M17N.exe temp.exe M17N.exe: M17N.cs M17NCore.dll mcs /r:M17NCore M17N.cs @@ -8,5 +8,8 @@ M17N.exe: M17N.cs M17NCore.dll M17NCore.dll: ${CORE_SRC} mcs /out:$@ /t:library ${CORE_SRC} +temp.exe: temp.cs M17NCore.dll + mcs /r:M17NCore temp.cs + clean: rm -f *.dll *.exe