diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-06-10 15:13:29 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-06-10 15:13:29 +0000 |
commit | 18278e3602831bb711ef1c69b92466c4e9f485ec (patch) | |
tree | 616ef208e38399b8db0c06e215c74c3c68fa6170 /src/cli/runtime/PersistentHashtableMap.cs | |
parent | 875c7c12aa5f20e02a3d3d08643e6eaaca61419a (diff) |
made ISequential
Diffstat (limited to 'src/cli/runtime/PersistentHashtableMap.cs')
-rw-r--r-- | src/cli/runtime/PersistentHashtableMap.cs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/cli/runtime/PersistentHashtableMap.cs b/src/cli/runtime/PersistentHashtableMap.cs index e00cd565..66732b72 100644 --- a/src/cli/runtime/PersistentHashtableMap.cs +++ b/src/cli/runtime/PersistentHashtableMap.cs @@ -152,6 +152,46 @@ public virtual IEnumerator GetEnumerator() { return new Iter(array);
}
+public ISeq seq() {
+ return Seq.create(array);
+}
+
+class Seq : ISeq{
+ PersistentArray buckets;
+ int b;
+ ISeq e;
+
+
+ static public Seq create(PersistentArray buckets) {
+ return next(buckets, -1, null);
+ }
+
+ static Seq next(PersistentArray buckets, int b, ISeq e) {
+ if(e != null && e.rest() != null)
+ return new Seq(buckets,b,e.rest());
+ for(b = b+1;b<buckets.length();b++)
+ {
+ ISequential a = (ISequential) buckets.get(b);
+ if(a != null && a.seq() != null)
+ return new Seq(buckets,b,a.seq());
+ }
+ return null;
+ }
+
+ Seq(PersistentArray buckets, int b, ISeq e) {
+ this.buckets = buckets;
+ this.b = b;
+ this.e = e;
+ }
+
+ public Object first() {
+ return e.first();
+ }
+
+ public ISeq rest() {
+ return next(buckets,b,e);
+ }
+}
internal class Iter : IEnumerator{
PersistentArray buckets;
|