fix PersistentSet.remove side-effect bug

The whole point of PersistentSet is to provide non-destructive write
operations, which means the add and remove methods should have no
effect on previous revisions.  However, a bug in remove caused shared
tree nodes to be modified, corrupting any revisions with which they
were shared.
This commit is contained in:
Joel Dice 2012-10-13 09:39:14 -06:00
parent a3c4b60f43
commit 3e0ab35ba1

View File

@ -252,7 +252,7 @@ public class PersistentSet <T> implements Iterable <T> {
}
ancestors.next = new Cell(n, ancestors.next);
sibling = ancestors.value.right;
sibling = ancestors.value.right = new Node(ancestors.value.right);
}
if (! (sibling.left.red || sibling.right.red)) {
@ -303,7 +303,7 @@ public class PersistentSet <T> implements Iterable <T> {
}
ancestors.next = new Cell(n, ancestors.next);
sibling = ancestors.value.left;
sibling = ancestors.value.left = new Node(ancestors.value.left);
}
if (! (sibling.right.red || sibling.left.red)) {