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:
Bill Jacobs
2016-07-22 17:03:36 -07:00
parent 5e23bd9c81
commit 9534c4ae06
3 changed files with 12 additions and 5 deletions

View File

@@ -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;