From 73f8a4754a43dfce194989457b54aceca5595979 Mon Sep 17 00:00:00 2001 From: Rich Hickey Date: Sat, 5 Aug 2006 17:06:27 +0000 Subject: renamed IArray, AnArray --- src/cli/runtime/APersistentArray.cs | 97 +++++++++++++++++++++++++++++++++ src/cli/runtime/AnArray.cs | 97 --------------------------------- src/cli/runtime/IArray.cs | 24 -------- src/cli/runtime/IPersistentArray.cs | 24 ++++++++ src/cli/runtime/PerisistentArrayList.cs | 4 +- src/cli/runtime/PersistentArray.cs | 18 +++--- src/cli/runtime/Tuple.cs | 8 +-- 7 files changed, 136 insertions(+), 136 deletions(-) create mode 100644 src/cli/runtime/APersistentArray.cs delete mode 100644 src/cli/runtime/AnArray.cs delete mode 100644 src/cli/runtime/IArray.cs create mode 100644 src/cli/runtime/IPersistentArray.cs (limited to 'src/cli/runtime') diff --git a/src/cli/runtime/APersistentArray.cs b/src/cli/runtime/APersistentArray.cs new file mode 100644 index 00000000..fe6a42f5 --- /dev/null +++ b/src/cli/runtime/APersistentArray.cs @@ -0,0 +1,97 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) + * which can be found in the file CPL.TXT at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + +using System; +using System.Collections; + +namespace clojure.lang +{ +public abstract class APersistentArray : Obj, IPersistentArray { + +public virtual IPersistentCollection cons(Object o) { + PersistentArrayList ret = new PersistentArrayList(this, this.count() + 10); + ret = (PersistentArrayList)ret.cons(o); + ret._meta = _meta; + return ret; +} + + public override Obj withMeta(IPersistentMap meta) + { + if(_meta == meta) + return this; + Obj ret = (Obj)MemberwiseClone(); + ret._meta = meta; + return ret; + } + + + #region IArray Members + + abstract public int length(); + + abstract public object nth(int i); + + abstract public IPersistentArray assocN(int i, object val); + + #endregion + + #region IPersistentCollection Members + + abstract public int count(); + + abstract public ISeq seq(); + + #endregion + +public bool contains(Object key) { + try{ + int i = Convert.ToInt32(key); + return i >= 0 && i < count(); + } + catch(Exception) + { + return false; + } +} + +public IMapEntry find(Object key) { + try + { + int i = Convert.ToInt32(key); + if(i >= 0 && i < count()) + return new MapEntry(key,nth(i)); + } + catch(Exception) + { + } + return null; +} + +public Associative assoc(Object key, Object val) { + int i = Convert.ToInt32(key); + return (Associative)assocN(i, val); +} + +public Object get(Object key) { + try + { + int i = Convert.ToInt32(key); + if(i >= 0 && i < count()) + return nth(i); + } + catch (Exception) + { + } + return null; + } + +} + +} diff --git a/src/cli/runtime/AnArray.cs b/src/cli/runtime/AnArray.cs deleted file mode 100644 index b02f7c65..00000000 --- a/src/cli/runtime/AnArray.cs +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Copyright (c) Rich Hickey. All rights reserved. - * The use and distribution terms for this software are covered by the - * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) - * which can be found in the file CPL.TXT at the root of this distribution. - * By using this software in any fashion, you are agreeing to be bound by - * the terms of this license. - * You must not remove this notice, or any other, from this software. - **/ - -using System; -using System.Collections; - -namespace clojure.lang -{ -public abstract class AnArray : Obj, IArray { - -public virtual IPersistentCollection cons(Object o) { - PersistentArrayList ret = new PersistentArrayList(this, this.count() + 10); - ret = (PersistentArrayList)ret.cons(o); - ret._meta = _meta; - return ret; -} - - public override Obj withMeta(IPersistentMap meta) - { - if(_meta == meta) - return this; - Obj ret = (Obj)MemberwiseClone(); - ret._meta = meta; - return ret; - } - - - #region IArray Members - - abstract public int length(); - - abstract public object nth(int i); - - abstract public IArray assocN(int i, object val); - - #endregion - - #region IPersistentCollection Members - - abstract public int count(); - - abstract public ISeq seq(); - - #endregion - -public bool contains(Object key) { - try{ - int i = Convert.ToInt32(key); - return i >= 0 && i < count(); - } - catch(Exception) - { - return false; - } -} - -public IMapEntry find(Object key) { - try - { - int i = Convert.ToInt32(key); - if(i >= 0 && i < count()) - return new MapEntry(key,nth(i)); - } - catch(Exception) - { - } - return null; -} - -public Associative assoc(Object key, Object val) { - int i = Convert.ToInt32(key); - return (Associative)assocN(i, val); -} - -public Object get(Object key) { - try - { - int i = Convert.ToInt32(key); - if(i >= 0 && i < count()) - return nth(i); - } - catch (Exception) - { - } - return null; - } - -} - -} diff --git a/src/cli/runtime/IArray.cs b/src/cli/runtime/IArray.cs deleted file mode 100644 index 09e1bbe6..00000000 --- a/src/cli/runtime/IArray.cs +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) Rich Hickey. All rights reserved. - * The use and distribution terms for this software are covered by the - * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) - * which can be found in the file CPL.TXT at the root of this distribution. - * By using this software in any fashion, you are agreeing to be bound by - * the terms of this license. - * You must not remove this notice, or any other, from this software. - */ - -using System; - -namespace clojure.lang -{ - -public interface IArray : IPersistentCollection, Associative, Sequential { -int length(); - -Object nth(int i); - -IArray assocN(int i,Object val); -} - -} diff --git a/src/cli/runtime/IPersistentArray.cs b/src/cli/runtime/IPersistentArray.cs new file mode 100644 index 00000000..77e6290c --- /dev/null +++ b/src/cli/runtime/IPersistentArray.cs @@ -0,0 +1,24 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) + * which can be found in the file CPL.TXT at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + */ + +using System; + +namespace clojure.lang +{ + +public interface IPersistentArray : Associative, Sequential { +int length(); + +Object nth(int i); + +IPersistentArray assocN(int i,Object val); +} + +} diff --git a/src/cli/runtime/PerisistentArrayList.cs b/src/cli/runtime/PerisistentArrayList.cs index 6753f4f1..3c71312a 100644 --- a/src/cli/runtime/PerisistentArrayList.cs +++ b/src/cli/runtime/PerisistentArrayList.cs @@ -33,7 +33,7 @@ PersistentArrayList(int size, Object defaultVal, float loadFactor, int count):ba this._count = count; } -public PersistentArrayList(IArray init, int initialCapacity):base(init,initialCapacity){ +public PersistentArrayList(IPersistentArray init, int initialCapacity):base(init,initialCapacity){ _count = Math.Min(init.count(),initialCapacity); } @@ -44,7 +44,7 @@ override public Object nth(int i) { return base.nth(i); } -override public IArray assocN(int i,Object val) { +override public IPersistentArray assocN(int i,Object val) { if(i >= _count) throw new IndexOutOfRangeException(); diff --git a/src/cli/runtime/PersistentArray.cs b/src/cli/runtime/PersistentArray.cs index f1e3fef5..8177a4b4 100644 --- a/src/cli/runtime/PersistentArray.cs +++ b/src/cli/runtime/PersistentArray.cs @@ -44,7 +44,7 @@ namespace clojure.lang * Java implementation is lock-free */ - public class PersistentArray : AnArray, IEnumerable + public class PersistentArray : APersistentArray, IEnumerable { #region IEnumerable Members @@ -242,7 +242,7 @@ public PersistentArray(int size, ISeq seq) : this(size){ data.master.load = load; } -public PersistentArray(IArray init) :this(init.length()) { +public PersistentArray(IPersistentArray init) :this(init.length()) { int load = 0; for(int i=0;i < init.length();i++) { @@ -253,7 +253,7 @@ public PersistentArray(IArray init) :this(init.length()) { data.master.load = load; } -public PersistentArray(IArray init, int size) :this(size) { +public PersistentArray(IPersistentArray init, int size) :this(size) { int load = 0; for(int i=0;i < init.length() && i < size;i++) { @@ -335,7 +335,7 @@ for (Entry e = (Entry)data.master.array[i]; e != null; e = e.rest()) return null; } -override public IArray assocN(int i,Object val) { +override public IPersistentArray assocN(int i,Object val) { //if (data.master.load >= data.master.maxLoad) // { // isolate(); @@ -410,9 +410,9 @@ protected void trim(){ override public bool Equals(Object key){ if(this == key) return true; - if(key == null || !(key is IArray)) return false; + if(key == null || !(key is IPersistentArray)) return false; - IArray a = (IArray) key; + IPersistentArray a = (IPersistentArray) key; if(a.length() != length()) return false; @@ -505,13 +505,13 @@ static public void Main(String[] args){ ArrayList v = ArrayList.Synchronized(new ArrayList(size)); //v.setSize(size); //IArray p = new PersistentArray(size); - IArray p = new PersistentArrayList(size); + IPersistentArray p = new PersistentArrayList(size); for(int i = 0; i < size; i++) { v.Add(0); //p = p.set(i, 0); - p = (IArray)((PersistentArrayList)p).cons(0); + p = (IPersistentArray)((PersistentArrayList)p).cons(0); } Random rand; @@ -535,7 +535,7 @@ static public void Main(String[] args){ rand = new Random(42); long tp = 0; start = DateTime.Now; - IArray oldp = p; + IPersistentArray oldp = p; for (int i = 0; i < writes; i++) { p = p.assocN(rand.Next(size), i); diff --git a/src/cli/runtime/Tuple.cs b/src/cli/runtime/Tuple.cs index fa6dfda1..24f7f760 100644 --- a/src/cli/runtime/Tuple.cs +++ b/src/cli/runtime/Tuple.cs @@ -15,7 +15,7 @@ using System; namespace clojure.lang { -public class Tuple : AnArray{ +public class Tuple : APersistentArray{ readonly Object[] array; @@ -42,7 +42,7 @@ override public Object nth(int i){ } -override public IArray assocN(int i, Object val) { +override public IPersistentArray assocN(int i, Object val) { Object[] newArray = (Object[])array.Clone(); newArray[i] = val; return new Tuple(newArray); @@ -50,9 +50,9 @@ override public IArray assocN(int i, Object val) { override public bool Equals(Object key){ if(this == key) return true; - if(key == null || !(key is IArray)) return false; + if(key == null || !(key is IPersistentArray)) return false; - IArray a = (IArray) key; + IPersistentArray a = (IPersistentArray) key; if(a.length() != array.Length) return false; -- cgit v1.2.3-70-g09d2