@@ -14,6 +14,8 @@ package scala
14
14
package collection
15
15
package immutable
16
16
17
+ import java .{util => ju }
18
+
17
19
import generic ._
18
20
import scala .annotation .unchecked .{uncheckedVariance => uV }
19
21
import parallel .immutable .ParHashMap
@@ -248,6 +250,18 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
248
250
protected override def merge0 [B1 >: B ](that : HashMap [A , B1 ], level : Int , merger : Merger [A , B1 ]): HashMap [A , B1 ] = {
249
251
that.updated0(key, hash, level, value, kv, merger.invert)
250
252
}
253
+
254
+ override def equals (that : Any ): Boolean = {
255
+ that match {
256
+ case hm : HashMap1 [_,_] =>
257
+ (this eq hm) ||
258
+ (hm.hash == hash && hm.key == key && hm.value == value)
259
+ case _ : HashMap [_, _] =>
260
+ false
261
+ case _ =>
262
+ super .equals(that)
263
+ }
264
+ }
251
265
}
252
266
253
267
private [collection] class HashMapCollision1 [A , + B ](private [collection] val hash : Int , val kvs : ListMap [A , B @ uV])
@@ -319,6 +333,19 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
319
333
for (p <- kvs) m = m.updated0(p._1, this .hash, level, p._2, p, merger.invert)
320
334
m
321
335
}
336
+
337
+ override def equals (that : Any ): Boolean = {
338
+ that match {
339
+ case hm : HashMapCollision1 [_,_] =>
340
+ (this eq hm) ||
341
+ (hm.hash == hash && hm.kvs == kvs)
342
+ case _ : HashMap [_, _] =>
343
+ false
344
+ case _ =>
345
+ super .equals(that)
346
+ }
347
+ }
348
+
322
349
}
323
350
324
351
@ deprecatedInheritance(" This class will be made final in a future release." , " 2.12.2" )
@@ -578,6 +605,22 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
578
605
case hm : HashMap [_, _] => this
579
606
case _ => sys.error(" section supposed to be unreachable." )
580
607
}
608
+
609
+ override def equals (that : Any ): Boolean = {
610
+ that match {
611
+ case hm : HashTrieMap [_, _] =>
612
+ (this eq hm) || {
613
+ this .bitmap == hm.bitmap &&
614
+ this .size0 == hm.size0 &&
615
+ ju.Arrays .equals(this .elems.asInstanceOf [Array [AnyRef ]], hm.elems.asInstanceOf [Array [AnyRef ]])
616
+ }
617
+ case _ : HashMap [_, _] =>
618
+ false
619
+ case _ =>
620
+ super .equals(that)
621
+ }
622
+ }
623
+
581
624
}
582
625
583
626
/**
0 commit comments