Skip to content

Commit 0dd15ef

Browse files
committed
[backport] Bulk ops on TreeSet, TreeMap prefer keys from the left
The test suite that aimed to bring all of our sets and maps into line did not exercise code paths optimized for: collection.$op(collectionOfSameType) This commit updates the test to: - add test variants that generate operands of the same type as the input collection - add "preserves identity" tests for set intersection - fix the resulting failures by flipping the operands in `RedBlackTree.{union,intersection}` I've also added concrete test cases to `Tree{Map,Set}Test` that are easier to review and that also exercise builders.
1 parent 046b650 commit 0dd15ef

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 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(t1, t2))
763+
def union[A, B](t1: Tree[A, B], t2: Tree[A, B])(implicit ordering: Ordering[A]): Tree[A, B] = blacken(_union(t2, t1))
764764

765-
def intersect[A, B](t1: Tree[A, B], t2: Tree[A, B])(implicit ordering: Ordering[A]): Tree[A, B] = blacken(_intersect(t1, t2))
765+
def intersect[A, B](t1: Tree[A, B], t2: Tree[A, B])(implicit ordering: Ordering[A]): Tree[A, B] = blacken(_intersect(t2, t1))
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]]))

0 commit comments

Comments
 (0)