ScalaのmutableのHashSetの面白い挙動

mutableのHashSet以外にも、 == と equals の違い、 ## と hashCode の違い、が関係ありややこしい。 ## や == は、単に hashCode や equals を呼ぶのではなく、少し特殊なことをしています。 ところで mutable な HashSet 内部で ## ではなく hashCode を使っているのは、修正するべきバグなのか、パフォーマンスなどの何かの理由があるのか?
1
Kenji Yoshida @xuwei_k

scala> val a = BigDecimal(42) a: scala.math.BigDecimal = 42 scala> a == a.toDouble res0: Boolean = true scala> List(a, a.toDouble).distinct res1: List[Any] = List(42, 42.0)

2017-12-30 00:55:02
Phil Derome @philderome

@xuwei_k scala> List(a.toDouble.asInstanceOf[Any] , a.asInstanceOf[Any]).toSet res2: scala.collection.immutable.Set[Any] = Set(42.0) scala> List(a.toDouble.asInstanceOf[Any] , a.asInstanceOf[Any]).distinct res3: List[Any] = List(42.0, 42)

2017-12-30 01:40:23
∃ugene -Yokota 🥙 mastodon.social/@eed3si9n @eed3si9n

@xuwei_k set aside the universal equality, the culprit here is lub on List.apply[A](...). I hope we will have a way to check for all lubbing in 2018.

2018-01-02 09:02:31
Dale Wijnand @dwijnand

@eed3si9n @xuwei_k I don't understand. How are they distinct if they are == each other? Shouldn't it still be using scala.math.BigDecimal#==?

2018-01-02 23:10:42
Kenji Yoshida @xuwei_k

@dwijnand @eed3si9n scala> val a = BigDecimal(42) a: scala.math.BigDecimal = 42 scala> val b = a.toDouble b: Double = 42.0 scala> a.## res0: Int = 42 scala> b.## res1: Int = 42 scala> a.hashCode res2: Int = 42 scala> b.hashCode res3: Int = 1078263808

2018-01-03 00:03:32
Kenji Yoshida @xuwei_k

@dwijnand List#distinct use mutable.HashSet mutable.HashSet use FlatHashTable FlatHashTable use hashCode ( not ## ) github.com/scala/scala/bl… github.com/scala/scala/bl… github.com/scala/scala/bl…

2018-01-03 00:08:00
Kenji Yoshida @xuwei_k

scala> val a = BigDecimal(7) a: scala.math.BigDecimal = 7 scala> val b = a.toDouble b: Double = 7.0 scala> collection.mutable.Set(a,b) res0: scala.collection.mutable.Set[Any] = Set(7, 7.0) scala> collection.immutable.Set(a,b) res1: scala.collection.immutable.Set[Any] = Set(7)

2018-01-03 00:10:23
Kevin Meredith @Gentmen

@eed3si9n @xuwei_k could you explain why the result is false for #1? @ List(x, x.toDouble).distinct res5: List[Any] = List(42, 42.0) @ Set(x, x.toDouble) res7: Set[Any] = Set(42) @ (x: Any) == (x.toDouble: Any) res13: Boolean = true thanks!

2018-01-03 00:11:42