diff --git a/RedBlackNode.jar b/RedBlackNode.jar index fac54d190..234edde7a 100644 Binary files a/RedBlackNode.jar and b/RedBlackNode.jar differ diff --git a/src/com/github/btrekkie/red_black_node/RedBlackNode.java b/src/com/github/btrekkie/red_black_node/RedBlackNode.java index 73a8dc535..671c35b6b 100644 --- a/src/com/github/btrekkie/red_black_node/RedBlackNode.java +++ b/src/com/github/btrekkie/red_black_node/RedBlackNode.java @@ -669,16 +669,17 @@ public abstract class RedBlackNode> implements Compara } /** - * Returns the root of a perfectly height-balanced subtree containing the next "size" nodes from "iterator", in - * iteration order. This method is responsible for setting the "left", "right", "parent", and isRed fields of the - * nodes, and calling augment() as appropriate. It ignores the initial values of the "left", "right", "parent", and - * isRed fields. + * Returns the root of a perfectly height-balanced subtree containing the next "size" (non-leaf) nodes from + * "iterator", in iteration order. This method is responsible for setting the "left", "right", "parent", and isRed + * fields of the nodes, and calling augment() as appropriate. It ignores the initial values of the "left", "right", + * "parent", and isRed fields. * @param iterator The nodes. * @param size The number of nodes. * @param height The "height" of the subtree's root node above the deepest leaf in the tree that contains it. Since * insertion fixup is slow if there are too many red nodes and deleteion fixup is slow if there are too few red * nodes, we compromise and have red nodes at every fourth level. We color a node red iff its "height" is equal * to 1 mod 4. + * @param leaf The leaf node. * @return The root of the subtree. */ private static > N createTree( @@ -740,8 +741,8 @@ public abstract class RedBlackNode> implements Compara // If the black height of "first", where first = this, is less than or equal to that of "last", starting at the // root of "last", we keep going left until we reach a black node whose black height is equal to that of // "first". Then, we make "pivot" the parent of that node and of "first", coloring it red, and perform - // insertion fixup on the pivot. If the black height of "first" is greater than that of "last", we do the mirror - // image of the above. + // insertion fixup on the pivot. If the black height of "first" is greater than that of "last", we do the + // mirror image of the above. if (parent != null) { throw new IllegalArgumentException("This is not the root of a tree"); @@ -831,10 +832,7 @@ public abstract class RedBlackNode> implements Compara * inserting all of the nodes in "last". */ public N concatenate(N last) { - if (parent != null) { - throw new IllegalArgumentException("The node is not the root of a tree"); - } - if (last.parent != null) { + if (parent != null || last.parent != null) { throw new IllegalArgumentException("The node is not the root of a tree"); } if (isLeaf()) { @@ -1221,10 +1219,7 @@ public abstract class RedBlackNode> implements Compara } else { int childBlackHeight; if (isRed) { - if (!left.isLeaf() && left.isRed) { - throw new RuntimeException("A red node has a red child"); - } - if (!right.isLeaf() && right.isRed) { + if ((!left.isLeaf() && left.isRed) || (!right.isLeaf() && right.isRed)) { throw new RuntimeException("A red node has a red child"); } childBlackHeight = blackHeight; diff --git a/src/com/github/btrekkie/tree_list/TreeList.java b/src/com/github/btrekkie/tree_list/TreeList.java index ba96c716f..41e411d91 100644 --- a/src/com/github/btrekkie/tree_list/TreeList.java +++ b/src/com/github/btrekkie/tree_list/TreeList.java @@ -398,7 +398,7 @@ public class TreeList extends AbstractList { } // Create the new node - TreeListNode newNode = new TreeListNode(value);; + TreeListNode newNode = new TreeListNode(value); newNode.left = leaf; newNode.right = leaf; newNode.isRed = true;