Skip to content

Commit 0da6e37

Browse files
committed
[backport] Refactor fix from prior commit
1 parent 0dd15ef commit 0da6e37

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

library/src/scala/collection/immutable/RedBlackTree.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,9 @@ private[collection] object RedBlackTree {
760760
// of child nodes from it. Where possible the black height is used directly instead of deriving the rank from it.
761761
// Our trees are supposed to have a black root so we always blacken as the last step of union/intersect/difference.
762762

763-
def union[A, B](t1: Tree[A, B], t2: Tree[A, B])(implicit ordering: Ordering[A]): Tree[A, B] = blacken(_union(t2, t1))
763+
def union[A, B](t1: Tree[A, B], t2: Tree[A, B])(implicit ordering: Ordering[A]): Tree[A, B] = blacken(_union(t1, t2))
764764

765-
def intersect[A, B](t1: Tree[A, B], t2: Tree[A, B])(implicit ordering: Ordering[A]): Tree[A, B] = blacken(_intersect(t2, t1))
765+
def intersect[A, B](t1: Tree[A, B], t2: Tree[A, B])(implicit ordering: Ordering[A]): Tree[A, B] = blacken(_intersect(t1, t2))
766766

767767
def difference[A, B](t1: Tree[A, B], t2: Tree[A, _])(implicit ordering: Ordering[A]): Tree[A, B] =
768768
blacken(_difference(t1, t2.asInstanceOf[Tree[A, B]]))
@@ -851,22 +851,22 @@ private[collection] object RedBlackTree {
851851

852852
private[this] def _union[A, B](t1: Tree[A, B], t2: Tree[A, B])(implicit ordering: Ordering[A]): Tree[A, B] =
853853
if((t1 eq null) || (t1 eq t2)) t2
854-
else if(t2 eq null) t1
854+
else if(t1 eq null) t2
855855
else {
856-
val (l1, _, r1) = split(t1, t2.key)
857-
val tl = _union(l1, t2.left)
858-
val tr = _union(r1, t2.right)
859-
join(tl, t2.key, t2.value, tr)
856+
val (l2, _, r2) = split(t2, t1.key)
857+
val tl = _union(t1.left, l2)
858+
val tr = _union(t1.right, r2)
859+
join(tl, t1.key, t1.value, tr)
860860
}
861861

862862
private[this] def _intersect[A, B](t1: Tree[A, B], t2: Tree[A, B])(implicit ordering: Ordering[A]): Tree[A, B] =
863863
if((t1 eq null) || (t2 eq null)) null
864864
else if (t1 eq t2) t1
865865
else {
866-
val (l1, b, r1) = split(t1, t2.key)
867-
val tl = _intersect(l1, t2.left)
868-
val tr = _intersect(r1, t2.right)
869-
if(b ne null) join(tl, t2.key, t2.value, tr)
866+
val (l2, b, r2) = split(t2, t1.key)
867+
val tl = _intersect(t1.left, l2)
868+
val tr = _intersect(t1.right, r2)
869+
if(b ne null) join(tl, t1.key, t1.value, tr)
870870
else join2(tl, tr)
871871
}
872872

0 commit comments

Comments
 (0)