Skip to content

Commit afca118

Browse files
authored
Merge pull request scala/scala#9062 from retronym/treeset-union-intersect
[backport] Bulk ops on TreeSet, TreeMap prefer keys from the left
2 parents f9e9f44 + 0da6e37 commit afca118

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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)