Skip to content

Commit 014b697

Browse files
author
Dave Abrahams
committed
isOrderedBefore: => by areInIncreasingOrder:
1 parent 4b072f6 commit 014b697

File tree

16 files changed

+114
-112
lines changed

16 files changed

+114
-112
lines changed

benchmark/single-source/SortStrings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ func benchSortStrings(_ words: [String]) {
10211021
// Notice that we _copy_ the array of words before we sort it.
10221022
// Pass an explicit '<' predicate to benchmark reabstraction thunks.
10231023
var tempwords = words
1024-
tempwords.sort(isOrderedBefore: <)
1024+
tempwords.sort(by: <)
10251025
}
10261026

10271027
public func run_SortStrings(_ N: Int) {

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,9 +2262,9 @@ public func expectEqualsUnordered<
22622262
Expected.Iterator.Element == Actual.Iterator.Element {
22632263

22642264
let x: [Expected.Iterator.Element] =
2265-
expected.sorted(isOrderedBefore: compose(compare, { $0.isLT() }))
2265+
expected.sorted(by: compose(compare, { $0.isLT() }))
22662266
let y: [Actual.Iterator.Element] =
2267-
actual.sorted(isOrderedBefore: compose(compare, { $0.isLT() }))
2267+
actual.sorted(by: compose(compare, { $0.isLT() }))
22682268
expectEqualSequence(
22692269
x, y, ${trace}, sameValue: compose(compare, { $0.isEQ() }))
22702270
}
@@ -2361,10 +2361,10 @@ public func expectEqualsUnordered<
23612361
}
23622362

23632363
let x: [(T, T)] =
2364-
expected.sorted(isOrderedBefore: comparePairLess)
2364+
expected.sorted(by: comparePairLess)
23652365
let y: [(T, T)] =
23662366
actual.map { ($0.0, $0.1) }
2367-
.sorted(isOrderedBefore: comparePairLess)
2367+
.sorted(by: comparePairLess)
23682368

23692369
func comparePairEquals(_ lhs: (T, T), rhs: (key: T, value: T)) -> Bool {
23702370
return lhs.0 == rhs.0 && lhs.1 == rhs.1

stdlib/public/core/CollectionAlgorithms.swift.gyb

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ orderingExplanation = """\
126126
/// is, for any elements `a`, `b`, and `c`, the following conditions must
127127
/// hold:
128128
///
129-
/// - `isOrderedBefore(a, a)` is always `false`. (Irreflexivity)
130-
/// - If `isOrderedBefore(a, b)` and `isOrderedBefore(b, c)` are both `true`,
131-
/// then `isOrderedBefore(a, c)` is also `true`. (Transitive
129+
/// - `areInIncreasingOrder(a, a)` is always `false`. (Irreflexivity)
130+
/// - If `areInIncreasingOrder(a, b)` and `areInIncreasingOrder(b, c)` are both `true`,
131+
/// then `areInIncreasingOrder(a, c)` is also `true`. (Transitive
132132
/// comparability)
133133
/// - Two elements are *incomparable* if neither is ordered before the other
134134
/// according to the predicate. If `a` and `b` are incomparable, and `b`
@@ -165,7 +165,7 @@ extension MutableCollection
165165
/// This method is typically one step of a sorting algorithm. A collection is
166166
/// partitioned around a pivot index when each of the elements before the
167167
/// pivot is correctly ordered before each of the elements at or after the
168-
/// pivot. The `partition(isOrderedBefore:)` method reorders the elements of
168+
/// pivot. The `partition(by:)` method reorders the elements of
169169
/// the collection and returns a pivot index that satisfies this condition,
170170
/// using the given predicate to determine the relative order of any two
171171
/// elements.
@@ -197,18 +197,18 @@ ${orderingExplanation}
197197
/// argument is greater than its second argument, larger elements are
198198
/// ordered before smaller elements.
199199
///
200-
/// - Parameter isOrderedBefore: A predicate that returns `true` if its first
200+
/// - Parameter areInIncreasingOrder: A predicate that returns `true` if its first
201201
/// argument should be ordered before its second argument; otherwise,
202202
/// `false`.
203203
/// - Returns: A pivot index, such that every element before the pivot is
204204
/// ordered before every element at or above the pivot, using
205-
/// `isOrderedBefore` to determine the relative order of any two elements.
205+
/// `areInIncreasingOrder` to determine the relative order of any two elements.
206206
/// The returned pivot is equal to the collection's end index only if the
207207
/// collection is empty.
208208
///
209209
/// - SeeAlso: `partition()`
210210
public mutating func partition(
211-
isOrderedBefore: @noescape (${IElement}, ${IElement}) -> Bool
211+
by areInIncreasingOrder: @noescape (${IElement}, ${IElement}) -> Bool
212212
) -> Index
213213

214214
% else:
@@ -248,7 +248,7 @@ ${orderingExplanation}
248248
/// less than every element at or above the pivot. The returned pivot is
249249
/// equal to the collection's end index only if the collection is empty.
250250
///
251-
/// - SeeAlso: `partition(isOrderedBefore:)`
251+
/// - SeeAlso: `partition(by:)`
252252
public mutating func partition() -> Index
253253

254254
% end
@@ -259,7 +259,7 @@ ${orderingExplanation}
259259
UnsafeMutableBufferPointer(start: baseAddress, count: count)
260260
let unsafeBufferPivot = bufferPointer.partition(
261261
% if preds:
262-
isOrderedBefore: isOrderedBefore
262+
by: areInIncreasingOrder
263263
% end
264264
)
265265
return unsafeBufferPivot - bufferPointer.startIndex
@@ -272,11 +272,11 @@ ${orderingExplanation}
272272
typealias EscapingBinaryPredicate =
273273
(${IElement}, ${IElement}) -> Bool
274274
var escapableIsOrderedBefore =
275-
unsafeBitCast(isOrderedBefore, to: EscapingBinaryPredicate.self)
275+
unsafeBitCast(areInIncreasingOrder, to: EscapingBinaryPredicate.self)
276276
return _partition(
277277
&self,
278278
subRange: startIndex..<endIndex,
279-
isOrderedBefore: &escapableIsOrderedBefore)
279+
by: &escapableIsOrderedBefore)
280280
% else:
281281
return _partition(&self, subRange: startIndex..<endIndex)
282282
% end
@@ -313,15 +313,15 @@ extension ${Self} where Self.Iterator.Element : Comparable {
313313
/// // Prints "["Abena", "Akosua", "Kofi", "Kweku", "Peter"]"
314314
///
315315
/// To sort the elements of your ${sequenceKind} in descending order, pass the
316-
/// greater-than operator (`>`) to the `sorted(isOrderedBefore:)` method.
316+
/// greater-than operator (`>`) to the `sorted(by:)` method.
317317
///
318-
/// let descendingStudents = students.sorted(isOrderedBefore: >)
318+
/// let descendingStudents = students.sorted(by: >)
319319
/// print(descendingStudents)
320320
/// // Prints "["Peter", "Kweku", "Kofi", "Akosua", "Abena"]"
321321
///
322322
/// - Returns: A sorted array of the ${sequenceKind}'s elements.
323323
///
324-
/// - SeeAlso: `sorted(isOrderedBefore:)`
324+
/// - SeeAlso: `sorted(by:)`
325325
/// ${'- MutatingVariant: sort' if Self == 'MutableCollection' else ''}
326326
public func sorted() -> [Iterator.Element] {
327327
var result = ContiguousArray(self)
@@ -342,7 +342,7 @@ extension ${Self} {
342342
///
343343
${orderingExplanation}
344344
/// The sorting algorithm is not stable. A nonstable sort may change the
345-
/// relative order of elements for which `isOrderedBefore` does not
345+
/// relative order of elements for which `areInIncreasingOrder` does not
346346
/// establish an order.
347347
///
348348
/// In the following example, the predicate provides an ordering for an array
@@ -375,10 +375,10 @@ ${orderingExplanation}
375375
/// You also use this method to sort elements that conform to the
376376
/// `Comparable` protocol in descending order. To sort your ${sequenceKind}
377377
/// in descending order, pass the greater-than operator (`>`) as the
378-
/// `isOrderedBefore` parameter.
378+
/// `areInIncreasingOrder` parameter.
379379
///
380380
/// let students: Set = ["Kofi", "Abena", "Peter", "Kweku", "Akosua"]
381-
/// let descendingStudents = students.sorted(isOrderedBefore: >)
381+
/// let descendingStudents = students.sorted(by: >)
382382
/// print(descendingStudents)
383383
/// // Prints "["Peter", "Kweku", "Kofi", "Akosua", "Abena"]"
384384
///
@@ -387,22 +387,22 @@ ${orderingExplanation}
387387
///
388388
/// print(students.sorted())
389389
/// // Prints "["Abena", "Akosua", "Kofi", "Kweku", "Peter"]"
390-
/// print(students.sorted(isOrderedBefore: <))
390+
/// print(students.sorted(by: <))
391391
/// // Prints "["Abena", "Akosua", "Kofi", "Kweku", "Peter"]"
392392
///
393-
/// - Parameter isOrderedBefore: A predicate that returns `true` if its first
393+
/// - Parameter areInIncreasingOrder: A predicate that returns `true` if its first
394394
/// argument should be ordered before its second argument; otherwise,
395395
/// `false`.
396396
/// - Returns: A sorted array of the ${sequenceKind}'s elements.
397397
///
398398
/// - SeeAlso: `sorted()`
399399
/// ${'- MutatingVariant: sort' if Self == 'MutableCollection' else ''}
400400
public func sorted(
401-
isOrderedBefore:
401+
by areInIncreasingOrder:
402402
@noescape (${IElement}, ${IElement}) -> Bool
403403
) -> [Iterator.Element] {
404404
var result = ContiguousArray(self)
405-
result.sort(isOrderedBefore: isOrderedBefore)
405+
result.sort(by: areInIncreasingOrder)
406406
return Array(result)
407407
}
408408
}
@@ -433,9 +433,9 @@ extension MutableCollection
433433
/// // Prints "["Abena", "Akosua", "Kofi", "Kweku", "Peter"]"
434434
///
435435
/// To sort the elements of your collection in descending order, pass the
436-
/// greater-than operator (`>`) to the `sort(isOrderedBefore:)` method.
436+
/// greater-than operator (`>`) to the `sort(by:)` method.
437437
///
438-
/// students.sort(isOrderedBefore: >)
438+
/// students.sort(by: >)
439439
/// print(students)
440440
/// // Prints "["Peter", "Kweku", "Kofi", "Akosua", "Abena"]"
441441
public mutating func sort() {
@@ -464,7 +464,7 @@ extension MutableCollection where Self : RandomAccessCollection {
464464
///
465465
${orderingExplanation}
466466
/// The sorting algorithm is not stable. A nonstable sort may change the
467-
/// relative order of elements for which `isOrderedBefore` does not
467+
/// relative order of elements for which `areInIncreasingOrder` does not
468468
/// establish an order.
469469
///
470470
/// In the following example, the closure provides an ordering for an array
@@ -501,35 +501,35 @@ ${orderingExplanation}
501501
/// predicate.
502502
///
503503
/// var students = ["Kofi", "Abena", "Peter", "Kweku", "Akosua"]
504-
/// students.sort(isOrderedBefore: >)
504+
/// students.sort(by: >)
505505
/// print(students)
506506
/// // Prints "["Peter", "Kweku", "Kofi", "Akosua", "Abena"]"
507507
///
508-
/// - Parameter isOrderedBefore: A predicate that returns `true` if its first
508+
/// - Parameter areInIncreasingOrder: A predicate that returns `true` if its first
509509
/// argument should be ordered before its second argument; otherwise,
510510
/// `false`.
511511
public mutating func sort(
512-
isOrderedBefore:
512+
by areInIncreasingOrder:
513513
@noescape (${IElement}, ${IElement}) -> Bool
514514
) {
515515
typealias EscapingBinaryPredicate =
516516
(Iterator.Element, Iterator.Element) -> Bool
517517
let escapableIsOrderedBefore =
518-
unsafeBitCast(isOrderedBefore, to: EscapingBinaryPredicate.self)
518+
unsafeBitCast(areInIncreasingOrder, to: EscapingBinaryPredicate.self)
519519

520520
let didSortUnsafeBuffer: Void? =
521521
_withUnsafeMutableBufferPointerIfSupported {
522522
(baseAddress, count) -> Void in
523523
var bufferPointer =
524524
UnsafeMutableBufferPointer(start: baseAddress, count: count)
525-
bufferPointer.sort(isOrderedBefore: escapableIsOrderedBefore)
525+
bufferPointer.sort(by: escapableIsOrderedBefore)
526526
return ()
527527
}
528528
if didSortUnsafeBuffer == nil {
529529
_introSort(
530530
&self,
531531
subRange: startIndex..<endIndex,
532-
isOrderedBefore: escapableIsOrderedBefore)
532+
by: escapableIsOrderedBefore)
533533
}
534534
}
535535
}
@@ -633,7 +633,7 @@ ${subscriptCommentPost}
633633

634634
extension MutableCollection where Self : RandomAccessCollection {
635635

636-
@available(*, unavailable, message: "slice the collection using the range, and call partition(isOrderedBefore:)")
636+
@available(*, unavailable, message: "slice the collection using the range, and call partition(by:)")
637637
public mutating func partition(
638638
_ range: Range<Index>,
639639
isOrderedBefore: (${IElement}, ${IElement}) -> Bool
@@ -663,7 +663,7 @@ extension MutableCollection
663663
}
664664

665665
extension MutableCollection where Self : RandomAccessCollection {
666-
@available(*, unavailable, renamed: "sort(isOrderedBefore:)")
666+
@available(*, unavailable, renamed: "sort(by:)")
667667
public mutating func sortInPlace(
668668
_ isOrderedBefore: @noescape (Iterator.Element, Iterator.Element) -> Bool
669669
) {

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ public func _setBridgeFromObjectiveCConditional<
15011501
/// "triangular": [1, 3, 6, 10, 15, 21, 28],
15021502
/// "hexagonal": [1, 6, 15, 28, 45, 66, 91]]
15031503
/// for key in interestingNumbers.keys {
1504-
/// interestingNumbers[key]?.sort(isOrderedBefore: >)
1504+
/// interestingNumbers[key]?.sort(by: >)
15051505
/// }
15061506
///
15071507
/// print(interestingNumbers["primes"]!)

0 commit comments

Comments
 (0)