diff options
| author | Rich Hickey <richhickey@gmail.com> | 2006-06-09 13:14:02 +0000 |
|---|---|---|
| committer | Rich Hickey <richhickey@gmail.com> | 2006-06-09 13:14:02 +0000 |
| commit | e4e5b0612f3acbcd223e8a7c27510bf9a2dde856 (patch) | |
| tree | 221c8f9ae40359b665ce65b02c2eaec4700b4948 /src/org | |
| parent | abb9f4e91313a368103e73f729de5792d3c5e435 (diff) | |
made ISequential
Diffstat (limited to 'src/org')
| -rw-r--r-- | src/org/clojure/runtime/PersistentListIdentityMap.java | 41 | ||||
| -rw-r--r-- | src/org/clojure/runtime/PersistentListMap.java | 74 |
2 files changed, 95 insertions, 20 deletions
diff --git a/src/org/clojure/runtime/PersistentListIdentityMap.java b/src/org/clojure/runtime/PersistentListIdentityMap.java index 7aa982b9..bd3bd4d4 100644 --- a/src/org/clojure/runtime/PersistentListIdentityMap.java +++ b/src/org/clojure/runtime/PersistentListIdentityMap.java @@ -28,7 +28,7 @@ import java.util.Iterator; * code duplication here is kind of gross, but most efficient
*/
-public class PersistentListIdentityMap implements IPersistentMap, IMapEntry
+public class PersistentListIdentityMap implements IPersistentMap, IMapEntry, ISeq, ISequential
{
static public PersistentListIdentityMap EMPTY = new PersistentListIdentityMap();
@@ -81,6 +81,19 @@ public int capacity(){ return 0;
}
+public Object first() {
+ return null;
+}
+
+public ISeq rest() {
+ return null;
+}
+
+public ISeq seq() {
+ return null;
+}
+
+
static class Iter implements Iterator{
PersistentListIdentityMap e;
@@ -168,6 +181,18 @@ static class Tail extends PersistentListIdentityMap { return EMPTY;
return this;
}
+
+ public Object first() {
+ return this;
+ }
+
+ public ISeq rest() {
+ return null;
+ }
+
+ public ISeq seq() {
+ return this;
+ }
}
static class Link extends PersistentListIdentityMap {
@@ -238,7 +263,19 @@ static class Link extends PersistentListIdentityMap { return count();
}
- PersistentListIdentityMap create(Object k,Object v,PersistentListIdentityMap r){
+ public Object first() {
+ return this;
+ }
+
+ public ISeq rest() {
+ return _rest;
+ }
+
+ public ISeq seq() {
+ return this;
+ }
+
+ PersistentListIdentityMap create(Object k,Object v,PersistentListIdentityMap r){
if(r == EMPTY)
return new Tail(k,v);
return new Link(k, v, r);
diff --git a/src/org/clojure/runtime/PersistentListMap.java b/src/org/clojure/runtime/PersistentListMap.java index 942d98cc..314da4cc 100644 --- a/src/org/clojure/runtime/PersistentListMap.java +++ b/src/org/clojure/runtime/PersistentListMap.java @@ -26,7 +26,7 @@ import java.util.Iterator; * * null keys and values are ok, but you won't be able to distinguish a null value via get - use contains/find */ -public class PersistentListMap implements IPersistentMap, IMapEntry +public class PersistentListMap implements IPersistentMap, IMapEntry, ISeq, ISequential { static public PersistentListMap EMPTY = new PersistentListMap(); @@ -35,6 +35,7 @@ static public PersistentListMap create(Object key, Object val){ return new Tail(key, val); } + public Object key(){ return null; } @@ -79,27 +80,39 @@ public int capacity(){ return 0; } +public Object first() { + return null; +} + +public ISeq rest() { + return null; +} + +public ISeq seq() { + return null; +} + static class Iter implements Iterator{ - PersistentListMap e; + PersistentListMap e; - Iter(PersistentListMap e) - { - this.e = e; - } + Iter(PersistentListMap e) + { + this.e = e; + } - public boolean hasNext(){ - return e != EMPTY; - } + public boolean hasNext(){ + return e != EMPTY; + } - public Object next(){ - PersistentListMap ret = e; - e = e.next(); - return ret; - } + public Object next(){ + PersistentListMap ret = e; + e = e.next(); + return ret; + } - public void remove(){ - throw new UnsupportedOperationException(); - } + public void remove(){ + throw new UnsupportedOperationException(); + } } public Iterator iterator(){ @@ -166,6 +179,19 @@ static class Tail extends PersistentListMap { return EMPTY; return this; } + + public Object first() { + return this; + } + + public ISeq rest() { + return null; + } + + public ISeq seq() { + return this; + } + } static class Link extends PersistentListMap { @@ -236,7 +262,19 @@ static class Link extends PersistentListMap { return count(); } - PersistentListMap create(Object k,Object v,PersistentListMap r){ + public Object first() { + return this; + } + + public ISeq rest() { + return _rest; + } + + public ISeq seq() { + return this; + } + + PersistentListMap create(Object k,Object v,PersistentListMap r){ if(r == EMPTY) return new Tail(k,v); return new Link(k, v, r); |
