KT-16602: Provide samples for sorting API usage

This commit is contained in:
Dat Trieu
2019-07-12 20:32:03 +02:00
committed by ilya-g
parent 3f5d64e635
commit 38d26b1d92
9 changed files with 180 additions and 0 deletions
@@ -1259,6 +1259,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
*/
public actual fun IntArray.sort(): Unit {
this.asDynamic().sort()
@@ -1266,6 +1268,8 @@ 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) }
@@ -1273,6 +1277,8 @@ public actual fun LongArray.sort(): Unit {
/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun ByteArray.sort(): Unit {
this.asDynamic().sort()
@@ -1280,6 +1286,8 @@ public actual fun ByteArray.sort(): Unit {
/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun ShortArray.sort(): Unit {
this.asDynamic().sort()
@@ -1287,6 +1295,8 @@ public actual fun ShortArray.sort(): Unit {
/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun DoubleArray.sort(): Unit {
this.asDynamic().sort()
@@ -1294,6 +1304,8 @@ public actual fun DoubleArray.sort(): Unit {
/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun FloatArray.sort(): Unit {
this.asDynamic().sort()
@@ -1301,6 +1313,8 @@ public actual fun FloatArray.sort(): Unit {
/**
* Sorts the array in-place.
*
* @sample samples.collections.Arrays.Sorting.sortArray
*/
public actual fun CharArray.sort(): Unit {
this.asDynamic().sort(::primitiveCompareTo)
@@ -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)