Skip to content

Commit 37e07bf

Browse files
committed
Handle empty test and NxD in subsetOf
1 parent 665d6a9 commit 37e07bf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library/src/scala/collection/immutable/HashSet.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ final class HashSet[A] private[immutable](private[immutable] val rootNode: Bitma
190190
* Stops iterating the first time that f returns `false`.*/
191191
@`inline` private[collection] def foreachWithHashWhile(f: (A, Int) => Boolean): Unit = rootNode.foreachWithHashWhile(f)
192192

193-
def subsetOf(that: Set[A]): Boolean = if (that.isEmpty) true else that match {
193+
def subsetOf(that: Set[A]): Boolean = isEmpty || !that.isEmpty && (that match {
194194
case set: HashSet[A] => rootNode.subsetOf(set.rootNode, 0)
195195
case _ => super.subsetOf(that)
196-
}
196+
})
197197

198198
override def equals(that: Any): Boolean =
199199
that match {
@@ -988,7 +988,7 @@ private final class BitmapIndexedSetNode[A](
988988
val elementHash = improve(elementUnimprovedHash)
989989
subNode.contains(payload, elementUnimprovedHash, elementHash, shift + BitPartitionSize)
990990
}
991-
} else {
991+
} else ((node.dataMap & bitpos) == 0) && {
992992
// Node x Node
993993
val subNode0 = this.getNode(indexFrom(this.nodeMap, bitpos))
994994
val subNode1 = node.getNode(indexFrom(node.nodeMap, bitpos))

0 commit comments

Comments
 (0)