summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli/runtime/PersistentArray.cs31
-rw-r--r--src/org/clojure/runtime/PersistentArray.java40
2 files changed, 62 insertions, 9 deletions
diff --git a/src/cli/runtime/PersistentArray.cs b/src/cli/runtime/PersistentArray.cs
index f9684901..71002269 100644
--- a/src/cli/runtime/PersistentArray.cs
+++ b/src/cli/runtime/PersistentArray.cs
@@ -44,7 +44,7 @@ namespace org.clojure.runtime
* Java implementation is lock-free
*/
-public class PersistentArray : IEnumerable{
+public class PersistentArray : IEnumerable, ISequential{
#region IEnumerable Members
@@ -54,7 +54,14 @@ public class PersistentArray : IEnumerable{
}
#endregion
-
+
+ public ISeq seq()
+ {
+ if (length() > 0)
+ return new Seq(this, 0);
+ return null;
+ }
+
internal class Master{
internal readonly Entry[] array;
internal readonly Object defaultVal;
@@ -111,6 +118,26 @@ internal class EntryLink : Entry
}
}
+internal class Seq : ISeq{
+ PersistentArray p;
+ int i;
+
+ internal Seq(PersistentArray p, int i){
+ this.p = p;
+ this.i = i;
+ }
+
+ public Object first() {
+ return p.get(i);
+ }
+
+ public ISeq rest() {
+ if(i+1 < p.length())
+ return new Seq(p, i + 1);
+ return null;
+ }
+}
+
internal class ValIter : IEnumerator
{
internal PersistentArray p;
diff --git a/src/org/clojure/runtime/PersistentArray.java b/src/org/clojure/runtime/PersistentArray.java
index b581ecf6..7c8bf52f 100644
--- a/src/org/clojure/runtime/PersistentArray.java
+++ b/src/org/clojure/runtime/PersistentArray.java
@@ -46,26 +46,32 @@ import java.util.Random;
* I added hybrid most-recent-sequential-range + shared-bitset idea, multi-thread-safety
*/
-public class PersistentArray implements Iterable{
+public class PersistentArray implements Iterable, ISequential{
public Iterator iterator(){
return new ValIter(this);
}
+public ISeq seq() {
+ if(length() > 0)
+ return new Seq(this, 0);
+ return null;
+}
+
static class Master{
- final Entry[] array;
- final Object defaultVal;
+ final Entry[] array;
+ final Object defaultVal;
int rev;
int load;
- final int maxLoad;
+ final int maxLoad;
final float loadFactor;
Master(int size,Object defaultVal, float loadFactor){
- this.array = new Entry[size];//new AtomicReferenceArray(size);
- this.defaultVal = defaultVal;
+ this.array = new Entry[size];//new AtomicReferenceArray(size);
+ this.defaultVal = defaultVal;
this.rev = 0;//new AtomicInteger(0);
this.load = 0;//new AtomicInteger(0);
- this.maxLoad = (int) (size * loadFactor);
+ this.maxLoad = (int) (size * loadFactor);
this.loadFactor = loadFactor;
}
}
@@ -103,6 +109,26 @@ static class EntryLink extends Entry{
}
}
+static class Seq implements ISeq{
+ PersistentArray p;
+ int i;
+
+ Seq(PersistentArray p, int i){
+ this.p = p;
+ this.i = i;
+ }
+
+ public Object first() {
+ return p.get(i);
+ }
+
+ public ISeq rest() {
+ if(i+1 < p.length())
+ return new Seq(p, i + 1);
+ return null;
+ }
+}
+
static class ValIter implements Iterator{
PersistentArray p;
int i;