Fixed RedBlackNode.concatenate on two one-node trees
This fixes RedBlackNode.concatenate to work on two one-node trees. The check for determining which tree had the greater red-black height was incorrect in that case.
This commit is contained in:
BIN
RedBlackNode.jar
BIN
RedBlackNode.jar
Binary file not shown.
@@ -772,9 +772,10 @@ public abstract class RedBlackNode<N extends RedBlackNode<N>> implements Compara
|
||||
N parent;
|
||||
if (firstBlackHeight <= lastBlackHeight) {
|
||||
parent = null;
|
||||
while (lastBlackHeight > firstBlackHeight) {
|
||||
int blackHeight = lastBlackHeight;
|
||||
while (blackHeight > firstBlackHeight) {
|
||||
if (!lastChild.isRed) {
|
||||
lastBlackHeight--;
|
||||
blackHeight--;
|
||||
}
|
||||
parent = lastChild;
|
||||
lastChild = lastChild.left;
|
||||
@@ -785,9 +786,10 @@ public abstract class RedBlackNode<N extends RedBlackNode<N>> implements Compara
|
||||
}
|
||||
} else {
|
||||
parent = null;
|
||||
while (firstBlackHeight > lastBlackHeight) {
|
||||
int blackHeight = firstBlackHeight;
|
||||
while (blackHeight > lastBlackHeight) {
|
||||
if (!firstChild.isRed) {
|
||||
firstBlackHeight--;
|
||||
blackHeight--;
|
||||
}
|
||||
parent = firstChild;
|
||||
firstChild = firstChild.right;
|
||||
@@ -802,7 +804,7 @@ public abstract class RedBlackNode<N extends RedBlackNode<N>> implements Compara
|
||||
pivot.isRed = true;
|
||||
pivot.parent = parent;
|
||||
if (parent != null) {
|
||||
if (parent.left == lastChild) {
|
||||
if (firstBlackHeight < lastBlackHeight) {
|
||||
parent.left = pivot;
|
||||
} else {
|
||||
parent.right = pivot;
|
||||
|
||||
@@ -72,6 +72,11 @@ public class TreeListTest {
|
||||
assertEquals(6, list.get(2).intValue());
|
||||
assertEquals(null, list.get(5));
|
||||
|
||||
list = new TreeList<Integer>();
|
||||
list.add(7);
|
||||
list.addAll(Collections.singleton(37));
|
||||
assertEquals(Arrays.asList(7, 37), list);
|
||||
|
||||
list = new TreeList<Integer>();
|
||||
for (int i = 0; i < 200; i++) {
|
||||
list.add(i + 300);
|
||||
|
||||
Reference in New Issue
Block a user