Skip to content

Commit

Permalink
KT-16602: Provide samples for sorting API usage
Browse files Browse the repository at this point in the history
(cherry picked from commit 38d26b1)
  • Loading branch information
Dattish authored and ilya-g committed Aug 21, 2019
1 parent 60c84e3 commit 9a7b61d
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libraries/stdlib/common/src/generated/_Arrays.kt
Expand Up @@ -6844,43 +6844,59 @@ public expect fun <T> Array<T>.plusElement(element: T): Array<T>

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public expect fun IntArray.sort(): Unit

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public expect fun LongArray.sort(): Unit

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public expect fun ByteArray.sort(): Unit

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public expect fun ShortArray.sort(): Unit

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public expect fun DoubleArray.sort(): Unit

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public expect fun FloatArray.sort(): Unit

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
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.
*
* @sample samples.collections.Arrays.Sorting.sortArrayOfComparable
*/
public expect fun <T : Comparable<T>> Array<out T>.sort(): Unit

Expand Down
8 changes: 8 additions & 0 deletions libraries/stdlib/common/src/generated/_UArrays.kt
Expand Up @@ -3484,6 +3484,8 @@ public inline operator fun UShortArray.plus(elements: UShortArray): UShortArray

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
Expand All @@ -3493,6 +3495,8 @@ public fun UIntArray.sort(): Unit {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
Expand All @@ -3502,6 +3506,8 @@ public fun ULongArray.sort(): Unit {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
Expand All @@ -3511,6 +3517,8 @@ public fun UByteArray.sort(): Unit {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
Expand Down
16 changes: 16 additions & 0 deletions libraries/stdlib/js-ir/src/generated/_ArraysJs.kt
Expand Up @@ -1403,48 +1403,62 @@ public actual inline fun <T> Array<out T>.plusElement(element: T): Array<T> {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun IntArray.sort(): Unit {
this.asDynamic().sort()
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun LongArray.sort(): Unit {
if (size > 1) sort { a: Long, b: Long -> a.compareTo(b) }
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun ByteArray.sort(): Unit {
this.asDynamic().sort()
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun ShortArray.sort(): Unit {
this.asDynamic().sort()
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun DoubleArray.sort(): Unit {
this.asDynamic().sort()
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun FloatArray.sort(): Unit {
this.asDynamic().sort()
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun CharArray.sort(): Unit {
this.asDynamic().sort(::primitiveCompareTo)
Expand All @@ -1454,6 +1468,8 @@ public actual 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.
*
* @sample samples.collections.Arrays.Sorting.sortArrayOfComparable
*/
public actual fun <T : Comparable<T>> Array<out T>.sort(): Unit {
if (size > 1) sortArray(this)
Expand Down
16 changes: 16 additions & 0 deletions libraries/stdlib/js/src/generated/_ArraysJs.kt
Expand Up @@ -1415,6 +1415,8 @@ public actual inline fun <T> Array<out T>.plusElement(element: T): Array<T> {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@library("primitiveArraySort")
public actual fun IntArray.sort(): Unit {
Expand All @@ -1423,13 +1425,17 @@ public actual fun IntArray.sort(): Unit {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun LongArray.sort(): Unit {
if (size > 1) sort { a: Long, b: Long -> a.compareTo(b) }
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@library("primitiveArraySort")
public actual fun ByteArray.sort(): Unit {
Expand All @@ -1438,6 +1444,8 @@ public actual fun ByteArray.sort(): Unit {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@library("primitiveArraySort")
public actual fun ShortArray.sort(): Unit {
Expand All @@ -1446,6 +1454,8 @@ public actual fun ShortArray.sort(): Unit {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@library("primitiveArraySort")
public actual fun DoubleArray.sort(): Unit {
Expand All @@ -1454,6 +1464,8 @@ public actual fun DoubleArray.sort(): Unit {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@library("primitiveArraySort")
public actual fun FloatArray.sort(): Unit {
Expand All @@ -1462,6 +1474,8 @@ public actual fun FloatArray.sort(): Unit {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@library("primitiveArraySort")
public actual fun CharArray.sort(): Unit {
Expand All @@ -1472,6 +1486,8 @@ public actual 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.
*
* @sample samples.collections.Arrays.Sorting.sortArrayOfComparable
*/
public actual fun <T : Comparable<T>> Array<out T>.sort(): Unit {
if (size > 1) sortArray(this)
Expand Down
32 changes: 32 additions & 0 deletions libraries/stdlib/jvm/src/generated/_ArraysJvm.kt
Expand Up @@ -1791,48 +1791,62 @@ public actual inline fun <T> Array<T>.plusElement(element: T): Array<T> {

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun IntArray.sort(): Unit {
if (size > 1) java.util.Arrays.sort(this)
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun LongArray.sort(): Unit {
if (size > 1) java.util.Arrays.sort(this)
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun ByteArray.sort(): Unit {
if (size > 1) java.util.Arrays.sort(this)
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun ShortArray.sort(): Unit {
if (size > 1) java.util.Arrays.sort(this)
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun DoubleArray.sort(): Unit {
if (size > 1) java.util.Arrays.sort(this)
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun FloatArray.sort(): Unit {
if (size > 1) java.util.Arrays.sort(this)
}

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun CharArray.sort(): Unit {
if (size > 1) java.util.Arrays.sort(this)
Expand All @@ -1842,6 +1856,8 @@ public actual 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.
*
* @sample samples.collections.Arrays.Sorting.sortArrayOfComparable
*/
@kotlin.internal.InlineOnly
public actual inline fun <T : Comparable<T>> Array<out T>.sort(): Unit {
Expand All @@ -1864,55 +1880,71 @@ public fun <T> Array<out T>.sort(): Unit {
* Sorts a range in the array in-place.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
*/
public fun <T> Array<out T>.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
java.util.Arrays.sort(this, fromIndex, toIndex)
}

/**
* Sorts a range in the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
*/
public fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
java.util.Arrays.sort(this, fromIndex, toIndex)
}

/**
* Sorts a range in the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
*/
public fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
java.util.Arrays.sort(this, fromIndex, toIndex)
}

/**
* Sorts a range in the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
*/
public fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
java.util.Arrays.sort(this, fromIndex, toIndex)
}

/**
* Sorts a range in the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
*/
public fun LongArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
java.util.Arrays.sort(this, fromIndex, toIndex)
}

/**
* Sorts a range in the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
*/
public fun FloatArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
java.util.Arrays.sort(this, fromIndex, toIndex)
}

/**
* Sorts a range in the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
*/
public fun DoubleArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
java.util.Arrays.sort(this, fromIndex, toIndex)
}

/**
* Sorts a range in the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
*/
public fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
java.util.Arrays.sort(this, fromIndex, toIndex)
Expand Down
Expand Up @@ -24,6 +24,7 @@ public inline fun <T> MutableList<T>.sort(comparison: (T, T) -> Int): Unit = thr
* Sorts elements in the list in-place according to their natural sort order.
*
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
* @sample samples.collections.Collections.Sorting.sortMutableList
*/
public actual fun <T : Comparable<T>> MutableList<T>.sort(): Unit {
if (size > 1) java.util.Collections.sort(this)
Expand Down

0 comments on commit 9a7b61d

Please sign in to comment.