Skip to content

Commit 536788b

Browse files
committed
Consistent syntax
1 parent 52e1e0e commit 536788b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Sources/Algorithms/Permutations.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ public struct Permutations<Base: Collection> {
3030
: 0
3131
}
3232
}
33-
33+
3434
extension Permutations: Sequence {
3535
/// The iterator for a `Permutations` instance.
3636
public struct Iterator: IteratorProtocol {
3737
@usableFromInline
3838
internal var base: Base
39+
3940
@usableFromInline
4041
internal var indexes: [Base.Index]
4142
@usableFromInline
@@ -83,28 +84,28 @@ extension Permutations: Sequence {
8384
@usableFromInline
8485
internal mutating func nextState() -> Bool {
8586
let edge = countToChoose - 1
86-
87+
8788
// Find first index greater than the one at `edge`.
8889
if let i = indexes[countToChoose...].firstIndex(where: { indexes[edge] < $0 }) {
8990
indexes.swapAt(edge, i)
9091
} else {
91-
indexes.reverse(subrange: countToChoose..<indexes.endIndex)
92-
92+
indexes.reverse(subrange: countToChoose ..< indexes.endIndex)
93+
9394
// Find last increasing pair below `edge`.
9495
// TODO: This could be indexes[..<edge].adjacentPairs().lastIndex(where: ...)
9596
var lastAscent = edge - 1
9697
while (lastAscent >= 0 && indexes[lastAscent] >= indexes[lastAscent + 1]) {
9798
lastAscent -= 1
9899
}
99-
if (lastAscent < 0) {
100+
if lastAscent < 0 {
100101
return false
101102
}
102-
103+
103104
// Find rightmost index less than that at `lastAscent`.
104105
if let i = indexes[lastAscent...].lastIndex(where: { indexes[lastAscent] < $0 }) {
105106
indexes.swapAt(lastAscent, i)
106107
}
107-
indexes.reverse(subrange: (lastAscent + 1)..<indexes.endIndex)
108+
indexes.reverse(subrange: (lastAscent + 1) ..< indexes.endIndex)
108109
}
109110

110111
return true
@@ -147,7 +148,7 @@ extension Permutations: LazySequenceProtocol where Base: LazySequenceProtocol {}
147148
//===----------------------------------------------------------------------===//
148149

149150
extension MutableCollection
150-
where Self: BidirectionalCollection, Element: Comparable
151+
where Self: BidirectionalCollection, Element: Comparable
151152
{
152153
/// Permutes this collection's elements through all the lexical orderings.
153154
///
@@ -178,7 +179,7 @@ extension MutableCollection
178179
formIndex(before: &j)
179180
}
180181
swapAt(i, j)
181-
self.reverse(subrange: ip1..<endIndex)
182+
self.reverse(subrange: ip1 ..< endIndex)
182183
return true
183184
}
184185

0 commit comments

Comments
 (0)