Permalink
Browse files

working on rbst

  • Loading branch information...
1 parent a0fc6bf commit 863e8ca06cbd094491e1d9c0c3673fb9d35a9830 @timm committed Jan 8, 2012
Showing with 10 additions and 5 deletions.
  1. +10 −5 build/lib/rbst.coffee
View
@@ -96,18 +96,23 @@ class RandomBinaryTree
h.n = x.n = null
h.right = x.left
x.left = h
- h.size(); x.size()
+ h.reset(); x.reset();
+ h.size() ; x.size()
x
rotateR: (h) ->
x = h.left
h.left = x.right
x.right = h
- h.size(); x.size()
+ h.reset(); x.reset();
+ h.size() ; x.size()
x
+ reset:() ->
+ @n = null
size:() ->
- @n = 1
- @n += @left.size() if @left
- @n += @right.size() if @right
+ unless @n
+ @n = 1
+ @n += @left.size() if @left
+ @n += @right.size() if @right
@n
# Inserting an Item

0 comments on commit 863e8ca

Please sign in to comment.