Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Minor bugfix to LLRedBlackTree. #1

Merged
merged 1 commit into from

2 participants

@mikelehen

I ran into an issue where doing a remove() would cause the value of another node to change (in addition to removing the node). Turned out to be a trivial fix. :-)

@mads379 mads379 merged commit 0a6534f into mads379:master
@mads379
Owner

Thank, nice catch Michael!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 20, 2012
  1. Fix typo in LLRedBlackTree remove() and add unit test.

    Michael Lehenbauer authored
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 3 deletions.
  1. +2 −2 src/LLRedBlackTree.coffee
  2. +8 −1 test/LLRedBlackTree.js
View
4 src/LLRedBlackTree.coffee
@@ -150,7 +150,7 @@ mugs.LLRBNode = (() ->
return new mugs.None()
else
smallest = min(n.right).get()
- n = n.copy(smallest.key,smallest.val,_,_,removeMin(n.right))
+ n = n.copy(smallest.key,smallest.value,_,_,removeMin(n.right))
n = n.copy(_,_,_,_,remove(n.right, key))
return new mugs.Some(fixUp(n))
@@ -305,4 +305,4 @@ mugs.LLRBLeaf.prototype.count = () -> 0
mugs.LLRBLeaf.prototype.isEmpty = () -> true
mugs.LLRBLeaf.prototype.containsKey = (key) -> false
mugs.LLRBLeaf.prototype.values = () -> new mugs.List()
-mugs.LLRBLeaf.prototype.inorderTraversal = (f) -> return
+mugs.LLRBLeaf.prototype.inorderTraversal = (f) -> return
View
9 test/LLRedBlackTree.js
@@ -55,6 +55,13 @@ $(document).ready(function(){
var n3 = node.remove(1);
});
+ test("Removal values", function(){
+ var node = new LLRBNode(2,2).insert(1,1).insert(3,3);
+ var n2 = node.remove(2);
+ ok(n2.get(1).get() === 1);
+ ok(n2.get(3).get() === 3);
+ });
+
test("Test increasing", function(){
var total = 100;
@@ -261,4 +268,4 @@ $(document).ready(function(){
ok(map.size() === 0);
});
-});
+});
Something went wrong with that request. Please try again.