File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ public struct Combinations<Base: Collection> {
14
14
/// The collection to iterate over for combinations.
15
15
public let base : Base
16
16
17
+ @usableFromInline
18
+ internal let baseCount : Int
19
+
17
20
/// The range of accepted sizes of combinations.
18
21
/// - Note: This may be `nil` if the attempted range entirely exceeds the
19
22
/// upper bounds of the size of the `base` collection.
@@ -40,17 +43,19 @@ public struct Combinations<Base: Collection> {
40
43
) where R. Bound == Int {
41
44
let range = kRange. relative ( to: 0 ..< . max)
42
45
self . base = base
43
- let upperBound = base. count + 1
46
+ let baseCount = base. count
47
+ self . baseCount = baseCount
48
+ let upperBound = baseCount + 1
44
49
self . kRange = range. lowerBound < upperBound
45
- ? range. clamped ( to: 0 ..< upperBound)
50
+ ? range. clamped ( to: 0 ..< upperBound)
46
51
: nil
47
52
}
48
53
49
54
/// The total number of combinations.
50
55
@inlinable
51
56
public var count : Int {
52
57
guard let k = self . kRange else { return 0 }
53
- let n = base . count
58
+ let n = baseCount
54
59
if k == 0 ..< ( n + 1 ) {
55
60
return 1 << n
56
61
}
You can’t perform that action at this time.
0 commit comments