@@ -146,7 +146,8 @@ private[collection] object RedBlackTree {
146146 private [this ] def minNodeAfter [A , B ](node : Node [A , B ] | Null , key : A )(implicit ord : Ordering [A ]): Node [A , B ] | Null = {
147147 if (node eq null ) null
148148 else {
149- var y : Node [A , B ] | Null = null
149+ // We know x is not null initially, so y will only be null before the first iteration of the loop.
150+ var y : Node [A , B ] = null .asInstanceOf [Node [A , B ]]
150151 var x : Node [A , B ] | Null = node
151152 var cmp = 1
152153 while ((x ne null ) && cmp != 0 ) {
@@ -176,7 +177,8 @@ private[collection] object RedBlackTree {
176177 private [this ] def maxNodeBefore [A , B ](node : Node [A , B ] | Null , key : A )(implicit ord : Ordering [A ]): Node [A , B ] | Null = {
177178 if (node eq null ) null
178179 else {
179- var y : Node [A , B ] | Null = null
180+ // We know x is not null initially, so y will only be null before the first iteration of the loop.
181+ var y : Node [A , B ] = null .asInstanceOf [Node [A , B ]]
180182 var x : Node [A , B ] | Null = node
181183 var cmp = 1
182184 while ((x ne null ) && cmp != 0 ) {
@@ -364,9 +366,8 @@ private[collection] object RedBlackTree {
364366 * Returns the node that follows `node` in an in-order tree traversal. If `node` has the maximum key (and is,
365367 * therefore, the last node), this method returns `null`.
366368 */
367- private [this ] def successor [A , B ](node : Node [A , B ] | Null ): Node [A , B ] | Null = {
368- if (node eq null ) null
369- else if (node.right ne null ) minNodeNonNull(node.right)
369+ private [this ] def successor [A , B ](node : Node [A , B ]): Node [A , B ] | Null = {
370+ if (node.right ne null ) minNodeNonNull(node.right)
370371 else {
371372 var x = node
372373 var y = x.parent
@@ -382,9 +383,8 @@ private[collection] object RedBlackTree {
382383 * Returns the node that precedes `node` in an in-order tree traversal. If `node` has the minimum key (and is,
383384 * therefore, the first node), this method returns `null`.
384385 */
385- private [this ] def predecessor [A , B ](node : Node [A , B ] | Null ): Node [A , B ] | Null = {
386- if (node eq null ) null
387- else if (node.left ne null ) maxNodeNonNull(node.left)
386+ private [this ] def predecessor [A , B ](node : Node [A , B ]): Node [A , B ] | Null = {
387+ if (node.left ne null ) maxNodeNonNull(node.left)
388388 else {
389389 var x = node
390390 var y = x.parent
0 commit comments