diff options
Diffstat (limited to 'src/cli/runtime')
-rw-r--r-- | src/cli/runtime/IPersistentMap.cs | 2 | ||||
-rw-r--r-- | src/cli/runtime/PersistentHashtableMap.cs | 40 | ||||
-rw-r--r-- | src/cli/runtime/PersistentHybridMap.cs | 11 |
3 files changed, 51 insertions, 2 deletions
diff --git a/src/cli/runtime/IPersistentMap.cs b/src/cli/runtime/IPersistentMap.cs index dc333eeb..aa072c56 100644 --- a/src/cli/runtime/IPersistentMap.cs +++ b/src/cli/runtime/IPersistentMap.cs @@ -14,7 +14,7 @@ using System.Collections; namespace org.clojure.runtime
{
-public interface IPersistentMap : IEnumerable{
+public interface IPersistentMap : IEnumerable, ISequential{
int count();
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;
diff --git a/src/cli/runtime/PersistentHybridMap.cs b/src/cli/runtime/PersistentHybridMap.cs index 5ca17c9c..7c0cc88e 100644 --- a/src/cli/runtime/PersistentHybridMap.cs +++ b/src/cli/runtime/PersistentHybridMap.cs @@ -100,6 +100,15 @@ virtual internal IPersistentMap createHashtableMap(int initialCapacity) { return new PersistentHashtableMap(initialCapacity);
}
-}
+
+#region ISequential Members
+
+public ISeq seq()
+ {
+ return impl.seq();
+ }
+
+#endregion
+ }
}
|