File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -608,4 +608,32 @@ extension _NativeSet {
608
608
return false
609
609
}
610
610
}
611
+
612
+ @_alwaysEmitIntoClient
613
+ internal func isStrictSubset< S: Sequence > ( of possibleSuperset: S ) -> Bool
614
+ where S. Element == Element {
615
+ _UnsafeBitset. withTemporaryBitset ( capacity: self . bucketCount) { seen in
616
+ // Mark elements in self that we've seen in `possibleSuperset`.
617
+ var seenCount = 0
618
+ var isStrict = false
619
+ for element in possibleSuperset {
620
+ let ( bucket, found) = find ( element)
621
+ guard found else {
622
+ if !isStrict {
623
+ isStrict = true
624
+ if seenCount == self . count { return true }
625
+ }
626
+ continue
627
+ }
628
+ let inserted = seen. uncheckedInsert ( bucket. offset)
629
+ if inserted {
630
+ seenCount += 1
631
+ if seenCount == self . count, isStrict {
632
+ return true
633
+ }
634
+ }
635
+ }
636
+ return false
637
+ }
638
+ }
611
639
}
Original file line number Diff line number Diff line change @@ -740,9 +740,10 @@ extension Set: SetAlgebra {
740
740
@inlinable
741
741
public func isStrictSubset< S: Sequence > ( of possibleStrictSuperset: S ) -> Bool
742
742
where S. Element == Element {
743
- // FIXME: code duplication.
744
- let other = Set ( possibleStrictSuperset)
745
- return isStrictSubset ( of: other)
743
+ if let s = possibleStrictSuperset as? Set < Element > {
744
+ return isStrictSubset ( of: s)
745
+ }
746
+ return _variant. convertedToNative. isStrictSubset ( of: possibleStrictSuperset)
746
747
}
747
748
748
749
/// Returns a Boolean value that indicates whether the set is a superset of
@@ -1211,7 +1212,7 @@ extension Set {
1211
1212
/// `other`; otherwise, `false`.
1212
1213
@inlinable
1213
1214
public func isStrictSubset( of other: Set < Element > ) -> Bool {
1214
- return other. isStrictSuperset ( of: self )
1215
+ return self . count < other. count && self . isSubset ( of: other )
1215
1216
}
1216
1217
1217
1218
/// Returns a new set with the elements that are common to both this set and
You can’t perform that action at this time.
0 commit comments