diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-08-04 23:43:39 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-08-04 23:43:39 +0000 |
commit | a8ba1dbdec6976596e005b7ffe2d06355280a10f (patch) | |
tree | 7f654417cb973198f22df97e3821d740a01b2613 | |
parent | cdd429f0d51b754ed0d2f4ab4cd9b90d320a3c0e (diff) |
added AnArray
-rw-r--r-- | src/cli/runtime/AnArray.cs | 45 | ||||
-rw-r--r-- | src/cli/runtime/PersistentArray.cs | 20 | ||||
-rw-r--r-- | src/cli/runtime/Tuple.cs | 12 | ||||
-rw-r--r-- | src/jvm/clojure/lang/AnArray.java | 27 | ||||
-rw-r--r-- | src/jvm/clojure/lang/PersistentArray.java | 14 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Tuple.java | 2 |
6 files changed, 89 insertions, 31 deletions
diff --git a/src/cli/runtime/AnArray.cs b/src/cli/runtime/AnArray.cs new file mode 100644 index 00000000..6bdb9d29 --- /dev/null +++ b/src/cli/runtime/AnArray.cs @@ -0,0 +1,45 @@ +/**
+ * 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 override Obj withMeta(IPersistentMap meta)
+ {
+ 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
+ }
+
+}
diff --git a/src/cli/runtime/PersistentArray.cs b/src/cli/runtime/PersistentArray.cs index 969833a5..3235eb44 100644 --- a/src/cli/runtime/PersistentArray.cs +++ b/src/cli/runtime/PersistentArray.cs @@ -44,7 +44,8 @@ namespace clojure.lang * Java implementation is lock-free
*/
-public class PersistentArray : Obj, IEnumerable, IArray{
+ public class PersistentArray : AnArray, IEnumerable
+ {
#region IEnumerable Members
@@ -55,19 +56,14 @@ public class PersistentArray : Obj, IEnumerable, IArray{ #endregion
- public ISeq seq()
+ override public ISeq seq()
{
if (length() > 0)
return new Seq(this, 0);
return null;
}
- public override Obj withMeta(IPersistentMap meta)
- {
- Obj ret = (Obj)MemberwiseClone();
- ret._meta = meta;
- return ret;
- }
+
internal class Master{
internal readonly Entry[] array;
@@ -257,15 +253,15 @@ public PersistentArray(IArray init) :this(init.length()) { data.master.load = load;
}
-virtual public int count(){
+override public int count(){
return data.master.array.Length;
}
-virtual public int length(){
+override public int length(){
return data.master.array.Length;
}
-virtual public Object nth(int i){
+override public Object nth(int i){
Entry e = getEntry(i);
if(e != null)
return e.val;
@@ -328,7 +324,7 @@ for (Entry e = (Entry)data.master.array[i]; e != null; e = e.rest()) return null;
}
-virtual public IArray assocN(int i,Object val) {
+override public IArray assocN(int i,Object val) {
//if (data.master.load >= data.master.maxLoad)
// {
// isolate();
diff --git a/src/cli/runtime/Tuple.cs b/src/cli/runtime/Tuple.cs index 07560fbf..fa6dfda1 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 : IArray{
+public class Tuple : AnArray{
readonly Object[] array;
@@ -29,20 +29,20 @@ public Tuple(params Object[] init){ this.array = init;
}
-public int count() {
+override public int count() {
return array.Length;
}
-public int length() {
+override public int length() {
return array.Length;
}
-public Object nth(int i){
+override public Object nth(int i){
return array[i];
}
-public IArray assocN(int i, Object val) {
+override public IArray assocN(int i, Object val) {
Object[] newArray = (Object[])array.Clone();
newArray[i] = val;
return new Tuple(newArray);
@@ -83,7 +83,7 @@ private bool equalKey(Object k1,Object k2){ return k1.Equals(k2);
}
-public ISeq seq() {
+override public ISeq seq() {
return ArraySeq.create(array);
}
}
diff --git a/src/jvm/clojure/lang/AnArray.java b/src/jvm/clojure/lang/AnArray.java new file mode 100644 index 00000000..0afe7c79 --- /dev/null +++ b/src/jvm/clojure/lang/AnArray.java @@ -0,0 +1,27 @@ +/**
+ * 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.
+ **/
+
+package clojure.lang;
+
+public abstract class AnArray extends Obj implements IArray, Cloneable {
+
+public Obj withMeta(IPersistentMap meta) {
+ try{
+ Obj ret = (Obj) clone();
+ ret._meta = meta;
+ return ret;
+ }
+ catch(CloneNotSupportedException ignore)
+ {
+ return null;
+ }
+}
+
+}
diff --git a/src/jvm/clojure/lang/PersistentArray.java b/src/jvm/clojure/lang/PersistentArray.java index 0b0ce5b7..2483c6bd 100644 --- a/src/jvm/clojure/lang/PersistentArray.java +++ b/src/jvm/clojure/lang/PersistentArray.java @@ -46,7 +46,7 @@ import java.util.Random; * I added hybrid most-recent-sequential-range + shared-bitset idea, multi-thread-safety */ -public class PersistentArray extends Obj implements Iterable, IArray, Cloneable { +public class PersistentArray extends AnArray implements Iterable { public Iterator iterator(){ return new ValIter(this); @@ -58,17 +58,7 @@ public ISeq seq() { return null; } -public Obj withMeta(IPersistentMap meta) { - try{ - Obj ret = (Obj) clone(); - ret._meta = meta; - return ret; - } - catch(CloneNotSupportedException ignore) - { - return null; - } -} + static class Master{ final Entry[] array; diff --git a/src/jvm/clojure/lang/Tuple.java b/src/jvm/clojure/lang/Tuple.java index da4cb152..3117227c 100644 --- a/src/jvm/clojure/lang/Tuple.java +++ b/src/jvm/clojure/lang/Tuple.java @@ -12,7 +12,7 @@ package clojure.lang; -public class Tuple implements IArray{ +public class Tuple extends AnArray{ final Object[] array; |