@@ -30,12 +30,13 @@ public struct Permutations<Base: Collection> {
30
30
: 0
31
31
}
32
32
}
33
-
33
+
34
34
extension Permutations : Sequence {
35
35
/// The iterator for a `Permutations` instance.
36
36
public struct Iterator : IteratorProtocol {
37
37
@usableFromInline
38
38
internal var base : Base
39
+
39
40
@usableFromInline
40
41
internal var indexes : [ Base . Index ]
41
42
@usableFromInline
@@ -83,28 +84,28 @@ extension Permutations: Sequence {
83
84
@usableFromInline
84
85
internal mutating func nextState( ) -> Bool {
85
86
let edge = countToChoose - 1
86
-
87
+
87
88
// Find first index greater than the one at `edge`.
88
89
if let i = indexes [ countToChoose... ] . firstIndex ( where: { indexes [ edge] < $0 } ) {
89
90
indexes. swapAt ( edge, i)
90
91
} else {
91
- indexes. reverse ( subrange: countToChoose..< indexes. endIndex)
92
-
92
+ indexes. reverse ( subrange: countToChoose ..< indexes. endIndex)
93
+
93
94
// Find last increasing pair below `edge`.
94
95
// TODO: This could be indexes[..<edge].adjacentPairs().lastIndex(where: ...)
95
96
var lastAscent = edge - 1
96
97
while ( lastAscent >= 0 && indexes [ lastAscent] >= indexes [ lastAscent + 1 ] ) {
97
98
lastAscent -= 1
98
99
}
99
- if ( lastAscent < 0 ) {
100
+ if lastAscent < 0 {
100
101
return false
101
102
}
102
-
103
+
103
104
// Find rightmost index less than that at `lastAscent`.
104
105
if let i = indexes [ lastAscent... ] . lastIndex ( where: { indexes [ lastAscent] < $0 } ) {
105
106
indexes. swapAt ( lastAscent, i)
106
107
}
107
- indexes. reverse ( subrange: ( lastAscent + 1 ) ..< indexes. endIndex)
108
+ indexes. reverse ( subrange: ( lastAscent + 1 ) ..< indexes. endIndex)
108
109
}
109
110
110
111
return true
@@ -147,7 +148,7 @@ extension Permutations: LazySequenceProtocol where Base: LazySequenceProtocol {}
147
148
//===----------------------------------------------------------------------===//
148
149
149
150
extension MutableCollection
150
- where Self: BidirectionalCollection , Element: Comparable
151
+ where Self: BidirectionalCollection , Element: Comparable
151
152
{
152
153
/// Permutes this collection's elements through all the lexical orderings.
153
154
///
@@ -178,7 +179,7 @@ extension MutableCollection
178
179
formIndex ( before: & j)
179
180
}
180
181
swapAt ( i, j)
181
- self . reverse ( subrange: ip1..< endIndex)
182
+ self . reverse ( subrange: ip1 ..< endIndex)
182
183
return true
183
184
}
184
185
0 commit comments