diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-08-09 14:45:16 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-08-09 14:45:16 +0000 |
commit | b9b9ceb459f528347f2433357697370fa3fa67b4 (patch) | |
tree | 0ebad3922bec9d4ec43d2d3c4ae372d53a204ea1 /src/cli/runtime/PersistentTreeMap.cs | |
parent | be12a746746c53c1f00758df7daa1fa5edc03935 (diff) |
made seq.count constant-time
Diffstat (limited to 'src/cli/runtime/PersistentTreeMap.cs')
-rw-r--r-- | src/cli/runtime/PersistentTreeMap.cs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/cli/runtime/PersistentTreeMap.cs b/src/cli/runtime/PersistentTreeMap.cs index cbf366c9..77be3e9f 100644 --- a/src/cli/runtime/PersistentTreeMap.cs +++ b/src/cli/runtime/PersistentTreeMap.cs @@ -89,13 +89,13 @@ override public IPersistentMap without(Object key){ override public ISeq seq() {
if(_count > 0)
- return Seq.create(tree, true);
+ return Seq.create(tree, true,_count);
return null;
} public ISeq rseq() {
if(_count > 0)
- return Seq.create(tree, false);
+ return Seq.create(tree, false,_count);
return null;
} @@ -636,14 +636,16 @@ class RedBranchVal : RedBranch{ public class Seq : ASeq{
readonly ISeq stack;
readonly bool asc;
+ readonly int cnt;
- Seq(ISeq stack, bool asc) {
+ Seq(ISeq stack, bool asc, int cnt) {
this.stack = stack;
this.asc = asc;
+ this.cnt = cnt;
}
- internal static Seq create(Node t, bool asc){
- return new Seq(push(t, null, asc),asc);
+ internal static Seq create(Node t, bool asc,int cnt){
+ return new Seq(push(t, null, asc),asc,cnt);
}
static ISeq push(Node t, ISeq stack, bool asc){
@@ -664,10 +666,15 @@ public class Seq : ASeq{ ISeq nextstack = push(asc ? t.right() : t.left(), stack.rest(), asc);
if(nextstack != null)
{
- return new Seq(nextstack,asc);
+ return new Seq(nextstack,asc,cnt-1);
}
return null;
}
+
+ public override int count()
+ {
+ return cnt;
+ }
}
|