[stdlib] Modernize sort code (#18824)

* Replace bodies of Comparable versions with calls to sort(by:)

* Make _insertionSort a method

* Make _sort3 a method

* Make _partition a method

* Make _introSort a method

* Make _siftDown, _heapify, _heapsort methods

* Other minor cleanup
This commit is contained in:
Ben Cohen
2018-08-19 11:36:10 -06:00
committed by GitHub
parent 82d4d1e207
commit bd310140f3
3 changed files with 264 additions and 300 deletions

View File

@@ -243,7 +243,7 @@ Algorithm.test("sort3/stable")
]) {
// decorate with offset, but sort by value
var input = Array($0.enumerated())
_sort3(&input, 0, 1, 2) { $0.element < $1.element }
input._sort3(0, 1, 2) { $0.element < $1.element }
// offsets should still be ordered for equal values
expectTrue(isSorted(input) {
if $0.element == $1.element {