Document that sorting is stable in each platform

#KT-12473 Fixed
This commit is contained in:
Ilya Gorbunov
2019-01-16 02:50:34 +03:00
parent 56672c2564
commit 0ac85ad715
10 changed files with 134 additions and 0 deletions
@@ -5040,6 +5040,8 @@ public fun CharArray.reversedArray(): CharArray {
/**
* Sorts elements in the array in-place according to natural sort order of the value returned by specified [selector] function.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public inline fun <T, R : Comparable<R>> Array<out T>.sortBy(crossinline selector: (T) -> R?): Unit {
if (size > 1) sortWith(compareBy(selector))
@@ -5047,6 +5049,8 @@ public inline fun <T, R : Comparable<R>> Array<out T>.sortBy(crossinline selecto
/**
* Sorts elements in the array in-place descending according to natural sort order of the value returned by specified [selector] function.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public inline fun <T, R : Comparable<R>> Array<out T>.sortByDescending(crossinline selector: (T) -> R?): Unit {
if (size > 1) sortWith(compareByDescending(selector))
@@ -5054,6 +5058,8 @@ public inline fun <T, R : Comparable<R>> Array<out T>.sortByDescending(crossinli
/**
* Sorts elements in the array in-place descending according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T : Comparable<T>> Array<out T>.sortDescending(): Unit {
sortWith(reverseOrder())
@@ -5131,6 +5137,8 @@ public fun CharArray.sortDescending(): Unit {
/**
* Returns a list of all elements sorted according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T : Comparable<T>> Array<out T>.sorted(): List<T> {
return sortedArray().asList()
@@ -5187,6 +5195,8 @@ public fun CharArray.sorted(): List<Char> {
/**
* Returns an array with all elements of this array sorted according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T : Comparable<T>> Array<T>.sortedArray(): Array<T> {
if (isEmpty()) return this
@@ -5251,6 +5261,8 @@ public fun CharArray.sortedArray(): CharArray {
/**
* Returns an array with all elements of this array sorted descending according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T : Comparable<T>> Array<T>.sortedArrayDescending(): Array<T> {
if (isEmpty()) return this
@@ -5315,6 +5327,8 @@ public fun CharArray.sortedArrayDescending(): CharArray {
/**
* Returns an array with all elements of this array sorted according the specified [comparator].
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T> Array<out T>.sortedArrayWith(comparator: Comparator<in T>): Array<out T> {
if (isEmpty()) return this
@@ -5323,6 +5337,8 @@ public fun <T> Array<out T>.sortedArrayWith(comparator: Comparator<in T>): Array
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public inline fun <T, R : Comparable<R>> Array<out T>.sortedBy(crossinline selector: (T) -> R?): List<T> {
return sortedWith(compareBy(selector))
@@ -5386,6 +5402,8 @@ public inline fun <R : Comparable<R>> CharArray.sortedBy(crossinline selector: (
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public inline fun <T, R : Comparable<R>> Array<out T>.sortedByDescending(crossinline selector: (T) -> R?): List<T> {
return sortedWith(compareByDescending(selector))
@@ -5449,6 +5467,8 @@ public inline fun <R : Comparable<R>> CharArray.sortedByDescending(crossinline s
/**
* Returns a list of all elements sorted descending according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T : Comparable<T>> Array<out T>.sortedDescending(): List<T> {
return sortedWith(reverseOrder())
@@ -5505,6 +5525,8 @@ public fun CharArray.sortedDescending(): List<Char> {
/**
* Returns a list of all elements sorted according to the specified [comparator].
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T> Array<out T>.sortedWith(comparator: Comparator<in T>): List<T> {
return sortedArrayWith(comparator).asList()
@@ -6702,11 +6724,15 @@ public expect fun CharArray.sort(): Unit
/**
* Sorts the array in-place according to the natural order of its elements.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public expect fun <T : Comparable<T>> Array<out T>.sort(): Unit
/**
* Sorts the array in-place according to the order specified by the given [comparator].
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public expect fun <T> Array<out T>.sortWith(comparator: Comparator<in T>): Unit
@@ -861,6 +861,8 @@ public fun <T> Iterable<T>.reversed(): List<T> {
/**
* Sorts elements in the list in-place according to natural sort order of the value returned by specified [selector] function.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public inline fun <T, R : Comparable<R>> MutableList<T>.sortBy(crossinline selector: (T) -> R?): Unit {
if (size > 1) sortWith(compareBy(selector))
@@ -868,6 +870,8 @@ public inline fun <T, R : Comparable<R>> MutableList<T>.sortBy(crossinline selec
/**
* Sorts elements in the list in-place descending according to natural sort order of the value returned by specified [selector] function.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public inline fun <T, R : Comparable<R>> MutableList<T>.sortByDescending(crossinline selector: (T) -> R?): Unit {
if (size > 1) sortWith(compareByDescending(selector))
@@ -875,6 +879,8 @@ public inline fun <T, R : Comparable<R>> MutableList<T>.sortByDescending(crossin
/**
* Sorts elements in the list in-place descending according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T : Comparable<T>> MutableList<T>.sortDescending(): Unit {
sortWith(reverseOrder())
@@ -882,6 +888,8 @@ public fun <T : Comparable<T>> MutableList<T>.sortDescending(): Unit {
/**
* Returns a list of all elements sorted according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T : Comparable<T>> Iterable<T>.sorted(): List<T> {
if (this is Collection) {
@@ -894,6 +902,8 @@ public fun <T : Comparable<T>> Iterable<T>.sorted(): List<T> {
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public inline fun <T, R : Comparable<R>> Iterable<T>.sortedBy(crossinline selector: (T) -> R?): List<T> {
return sortedWith(compareBy(selector))
@@ -901,6 +911,8 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.sortedBy(crossinline select
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public inline fun <T, R : Comparable<R>> Iterable<T>.sortedByDescending(crossinline selector: (T) -> R?): List<T> {
return sortedWith(compareByDescending(selector))
@@ -908,6 +920,8 @@ public inline fun <T, R : Comparable<R>> Iterable<T>.sortedByDescending(crossinl
/**
* Returns a list of all elements sorted descending according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T : Comparable<T>> Iterable<T>.sortedDescending(): List<T> {
return sortedWith(reverseOrder())
@@ -915,6 +929,8 @@ public fun <T : Comparable<T>> Iterable<T>.sortedDescending(): List<T> {
/**
* Returns a list of all elements sorted according to the specified [comparator].
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*/
public fun <T> Iterable<T>.sortedWith(comparator: Comparator<in T>): List<T> {
if (this is Collection) {
@@ -502,6 +502,8 @@ public fun <T> Sequence<T>.takeWhile(predicate: (T) -> Boolean): Sequence<T> {
/**
* Returns a sequence that yields elements of this sequence sorted according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*
* The operation is _intermediate_ and _stateful_.
*/
@@ -517,6 +519,8 @@ public fun <T : Comparable<T>> Sequence<T>.sorted(): Sequence<T> {
/**
* Returns a sequence that yields elements of this sequence sorted according to natural sort order of the value returned by specified [selector] function.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*
* The operation is _intermediate_ and _stateful_.
*/
@@ -526,6 +530,8 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.sortedBy(crossinline select
/**
* Returns a sequence that yields elements of this sequence sorted descending according to natural sort order of the value returned by specified [selector] function.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*
* The operation is _intermediate_ and _stateful_.
*/
@@ -535,6 +541,8 @@ public inline fun <T, R : Comparable<R>> Sequence<T>.sortedByDescending(crossinl
/**
* Returns a sequence that yields elements of this sequence sorted descending according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*
* The operation is _intermediate_ and _stateful_.
*/
@@ -544,6 +552,8 @@ public fun <T : Comparable<T>> Sequence<T>.sortedDescending(): Sequence<T> {
/**
* Returns a sequence that yields elements of this sequence sorted according to the specified [comparator].
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*
* The operation is _intermediate_ and _stateful_.
*/