@@ -14,6 +14,8 @@ package scala
14
14
package collection
15
15
package immutable
16
16
17
+ import java .util
18
+
17
19
import generic ._
18
20
import scala .collection .parallel .immutable .ParHashSet
19
21
import scala .collection .GenSet
@@ -258,12 +260,21 @@ object HashSet extends ImmutableSetFactory[HashSet] {
258
260
override protected def get0 (key : A , hash : Int , level : Int ): Boolean =
259
261
(hash == this .hash && key == this .key)
260
262
263
+ override def equals (other : Any ): Boolean = {
264
+ other match {
265
+ case that : HashSet1 [A ] =>
266
+ (this eq that) || (this .hash == that.hash && this .key == that.key)
267
+ case _ : HashSet [_] => false
268
+ case _ => super .equals(other)
269
+ }
270
+ }
271
+
261
272
override protected def subsetOf0 (that : HashSet [A ], level : Int ) = {
262
273
// check if that contains this.key
263
274
// we use get0 with our key and hash at the correct level instead of calling contains,
264
275
// which would not work since that might not be a top-level HashSet
265
276
// and in any case would be inefficient because it would require recalculating the hash code
266
- that.get0(key, hash, level)
277
+ ( this eq that) || that.get0(key, hash, level)
267
278
}
268
279
269
280
override private [collection] def updated0 (key : A , hash : Int , level : Int ): HashSet [A ] =
@@ -328,12 +339,21 @@ object HashSet extends ImmutableSetFactory[HashSet] {
328
339
override protected def get0 (key : A , hash : Int , level : Int ): Boolean =
329
340
if (hash == this .hash) ks.contains(key) else false
330
341
342
+ override def equals (other : Any ): Boolean = {
343
+ other match {
344
+ case that : HashSetCollision1 [A ] =>
345
+ (this eq that) || (this .hash == that.hash && this .ks == that.ks)
346
+ case miss : HashSet [_] => false
347
+ case _ => super .equals(other)
348
+ }
349
+ }
350
+
331
351
override protected def subsetOf0 (that : HashSet [A ], level : Int ) = {
332
352
// we have to check each element
333
353
// we use get0 with our hash at the correct level instead of calling contains,
334
354
// which would not work since that might not be a top-level HashSet
335
355
// and in any case would be inefficient because it would require recalculating the hash code
336
- ks.forall(key => that.get0(key, hash, level))
356
+ ( this eq that) || ks.forall(key => that.get0(key, hash, level))
337
357
}
338
358
339
359
override private [collection] def updated0 (key : A , hash : Int , level : Int ): HashSet [A ] =
@@ -878,7 +898,17 @@ object HashSet extends ImmutableSetFactory[HashSet] {
878
898
}
879
899
}
880
900
881
- override protected def subsetOf0 (that : HashSet [A ], level : Int ): Boolean = if (that eq this ) true else that match {
901
+ override def equals (other : Any ): Boolean = {
902
+ other match {
903
+ case that : HashTrieSet [A ] =>
904
+ (this eq that) || (this .bitmap == that.bitmap && this .size0 == that.size0 &&
905
+ util.Arrays .equals(this .elems.asInstanceOf [Array [AnyRef ]], that.elems.asInstanceOf [Array [AnyRef ]]))
906
+ case _ : HashSet [_] => false
907
+ case _ => super .equals(other)
908
+ }
909
+ }
910
+
911
+ override protected def subsetOf0 (that : HashSet [A ], level : Int ): Boolean = (that eq this ) || (that match {
882
912
case that : HashTrieSet [A ] if this .size0 <= that.size0 =>
883
913
// create local mutable copies of members
884
914
var abm = this .bitmap
@@ -919,7 +949,7 @@ object HashSet extends ImmutableSetFactory[HashSet] {
919
949
// if the other set is a HashSetCollision1, we can not be a subset of it because we are a HashTrieSet with at least two different hash codes
920
950
// if the other set is the empty set, we are not a subset of it because we are not empty
921
951
false
922
- }
952
+ })
923
953
924
954
override protected def filter0 (p : A => Boolean , negate : Boolean , level : Int , buffer : Array [HashSet [A ]], offset0 : Int ): HashSet [A ] = {
925
955
// current offset
0 commit comments