@@ -146,7 +146,8 @@ private[collection] object RedBlackTree {
146
146
private [this ] def minNodeAfter [A , B ](node : Node [A , B ] | Null , key : A )(implicit ord : Ordering [A ]): Node [A , B ] | Null = {
147
147
if (node eq null ) null
148
148
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 ]]
150
151
var x : Node [A , B ] | Null = node
151
152
var cmp = 1
152
153
while ((x ne null ) && cmp != 0 ) {
@@ -176,7 +177,8 @@ private[collection] object RedBlackTree {
176
177
private [this ] def maxNodeBefore [A , B ](node : Node [A , B ] | Null , key : A )(implicit ord : Ordering [A ]): Node [A , B ] | Null = {
177
178
if (node eq null ) null
178
179
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 ]]
180
182
var x : Node [A , B ] | Null = node
181
183
var cmp = 1
182
184
while ((x ne null ) && cmp != 0 ) {
@@ -364,9 +366,8 @@ private[collection] object RedBlackTree {
364
366
* Returns the node that follows `node` in an in-order tree traversal. If `node` has the maximum key (and is,
365
367
* therefore, the last node), this method returns `null`.
366
368
*/
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)
370
371
else {
371
372
var x = node
372
373
var y = x.parent
@@ -382,9 +383,8 @@ private[collection] object RedBlackTree {
382
383
* Returns the node that precedes `node` in an in-order tree traversal. If `node` has the minimum key (and is,
383
384
* therefore, the first node), this method returns `null`.
384
385
*/
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)
388
388
else {
389
389
var x = node
390
390
var y = x.parent
0 commit comments