Skip to content

Don't check key equality in RedBlackTree#8783

Merged
lrytz merged 1 commit intoscala:2.13.xfrom
szeiger:wip/rbt-key-equality
Apr 3, 2020
Merged

Don't check key equality in RedBlackTree#8783
lrytz merged 1 commit intoscala:2.13.xfrom
szeiger:wip/rbt-key-equality

Conversation

@szeiger
Copy link
Contributor

@szeiger szeiger commented Mar 3, 2020

This was left over from 2.12 when they old key would be overwritten.
The behavior changed in #7481 to
comply with the new map/set rules in
scala/bug#10415 (comment).

I would also call it wrong in 2.12 because equality should be defined
exclusively by the Ordering, but we should keep the current behavior
for compatibility reasons.

This was left over from 2.12 when they old key would be overwritten.
The behavior changed in scala#7481 to
comply with the new map/set rules in
scala/bug#10415 (comment).

I would also call it wrong in 2.12 because equality should be defined
exclusively by the Ordering, but we should keep the current behavior
for compatibility reasons.
@scala-jenkins scala-jenkins added this to the 2.13.3 milestone Mar 3, 2020
@szeiger
Copy link
Contributor Author

szeiger commented Mar 3, 2020

based on a chat with @mkeskells who noticed the change when backporting the new RedBlackTree code

@mkeskells
Copy link
Contributor

should this me marked [nomerge] or similar to avoid an automatic merge to 2.12 in the future?

@szeiger
Copy link
Contributor Author

szeiger commented Mar 6, 2020

We only merge forward, not backward.

@diesalbla diesalbla added the library:collections PRs involving changes to the standard collection library label Mar 17, 2020
@lrytz lrytz modified the milestones: 2.13.3, 2.13.2 Mar 30, 2020
@SethTisue
Copy link
Member

this looks plausible, but I don't know the code well enough to easily do a proper review. is Mike's implied signoff enough? (and, should there be a test?)

@lrytz
Copy link
Member

lrytz commented Apr 3, 2020

This PR is only a cleanup, it doesn't change behavior. In 2.13.1:

scala> collection.immutable.TreeMap.apply(2 -> 2)(Ordering.by(x => x/2)).updated(3, 3)
res0: scala.collection.immutable.TreeMap[Int,Int] = TreeMap(2 -> 3)

Same with this PR:

scala> collection.immutable.TreeMap.apply(2 -> 2)(Ordering.by(x => x/2)).updated(3, 3)
val res0: scala.collection.immutable.TreeMap[Int,Int] = TreeMap(2 -> 3)

Whereas in 2.12.11

scala> collection.immutable.TreeMap.apply(2 -> 2)(Ordering.by(x => x/2)).updated(3, 3)
res0: scala.collection.immutable.TreeMap[Int,Int] = Map(3 -> 3)

@lrytz lrytz merged commit b51377f into scala:2.13.x Apr 3, 2020
@lrytz
Copy link
Member

lrytz commented Apr 3, 2020

The observable change is this:

scala> val s = collection.immutable.TreeSet(2)(Ordering.by(x => x/2))
val s: scala.collection.immutable.TreeSet[Int] = TreeSet(2)

scala> s eq (s + 3)
val res2: Boolean = true

in 2.13.1 this was false.

retronym added a commit to retronym/scala that referenced this pull request May 20, 2020
Erroneous commit was:

```
commit 2c620a7
Merge: abcde58 8270221
Author: Jason Zaugg <jzaugg@gmail.com>
Date:   Thu May 14 11:17:30 2020 +1000

    Merge commit '8270221567' into merge/2.12.x-to-2.13.x-20200514
```

According to scala#8783, which removed `|| k != tree.key`,
there was no behaviour change in 2.13.x, this was just a cleanup.
retronym added a commit to retronym/scala that referenced this pull request May 20, 2020
hamzaremmal pushed a commit to hamzaremmal/scala3 that referenced this pull request May 2, 2025
hamzaremmal pushed a commit to hamzaremmal/scala3 that referenced this pull request May 2, 2025
Erroneous commit was:

```
commit b42349c
Merge: 481bb48 a41e72c
Author: Jason Zaugg <jzaugg@gmail.com>
Date:   Thu May 14 11:17:30 2020 +1000

    Merge commit 'a41e72c988' into merge/2.12.x-to-2.13.x-20200514
```

According to scala/scala#8783, which removed `|| k != tree.key`,
there was no behaviour change in 2.13.x, this was just a cleanup.
hamzaremmal pushed a commit to hamzaremmal/scala3 that referenced this pull request May 2, 2025
hamzaremmal pushed a commit to scala/scala3 that referenced this pull request May 7, 2025
hamzaremmal pushed a commit to scala/scala3 that referenced this pull request May 7, 2025
Erroneous commit was:

```
commit 3bb47b3
Merge: b3ffa32 35910d2
Author: Jason Zaugg <jzaugg@gmail.com>
Date:   Thu May 14 11:17:30 2020 +1000

    Merge commit '35910d2a8a' into merge/2.12.x-to-2.13.x-20200514
```

According to scala/scala#8783, which removed `|| k != tree.key`,
there was no behaviour change in 2.13.x, this was just a cleanup.
hamzaremmal pushed a commit to scala/scala3 that referenced this pull request May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

library:collections PRs involving changes to the standard collection library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants