Skip to content

Commit

Permalink
KT-16602: Provide samples for sorting API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Dattish authored and ilya-g committed Jul 12, 2019
1 parent 3f5d64e commit 38d26b1
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 @@ -6736,43 +6736,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 @@ -3424,6 +3424,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 @@ -3433,6 +3435,8 @@ public fun UIntArray.sort(): Unit {

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

/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
Expand All @@ -3451,6 +3457,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 @@ -1259,48 +1259,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 @@ -1310,6 +1324,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 @@ -1271,6 +1271,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 @@ -1279,13 +1281,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 @@ -1294,6 +1300,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 @@ -1302,6 +1310,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 @@ -1310,6 +1320,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 @@ -1318,6 +1330,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 @@ -1328,6 +1342,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 @@ -1728,48 +1728,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 @@ -1779,6 +1793,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 @@ -1801,55 +1817,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 38d26b1

Please sign in to comment.