Skip to content

Commit 9a7b61d

Browse files
Dattishilya-g
authored andcommitted
KT-16602: Provide samples for sorting API usage
(cherry picked from commit 38d26b1)
1 parent 60c84e3 commit 9a7b61d

File tree

9 files changed

+180
-0
lines changed

9 files changed

+180
-0
lines changed

libraries/stdlib/common/src/generated/_Arrays.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6844,43 +6844,59 @@ public expect fun <T> Array<T>.plusElement(element: T): Array<T>
68446844

68456845
/**
68466846
* Sorts the array in-place.
6847+
*
6848+
* @sample samples.collections.Arrays.Sorting.sortArray
68476849
*/
68486850
public expect fun IntArray.sort(): Unit
68496851

68506852
/**
68516853
* Sorts the array in-place.
6854+
*
6855+
* @sample samples.collections.Arrays.Sorting.sortArray
68526856
*/
68536857
public expect fun LongArray.sort(): Unit
68546858

68556859
/**
68566860
* Sorts the array in-place.
6861+
*
6862+
* @sample samples.collections.Arrays.Sorting.sortArray
68576863
*/
68586864
public expect fun ByteArray.sort(): Unit
68596865

68606866
/**
68616867
* Sorts the array in-place.
6868+
*
6869+
* @sample samples.collections.Arrays.Sorting.sortArray
68626870
*/
68636871
public expect fun ShortArray.sort(): Unit
68646872

68656873
/**
68666874
* Sorts the array in-place.
6875+
*
6876+
* @sample samples.collections.Arrays.Sorting.sortArray
68676877
*/
68686878
public expect fun DoubleArray.sort(): Unit
68696879

68706880
/**
68716881
* Sorts the array in-place.
6882+
*
6883+
* @sample samples.collections.Arrays.Sorting.sortArray
68726884
*/
68736885
public expect fun FloatArray.sort(): Unit
68746886

68756887
/**
68766888
* Sorts the array in-place.
6889+
*
6890+
* @sample samples.collections.Arrays.Sorting.sortArray
68776891
*/
68786892
public expect fun CharArray.sort(): Unit
68796893

68806894
/**
68816895
* Sorts the array in-place according to the natural order of its elements.
68826896
*
68836897
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
6898+
*
6899+
* @sample samples.collections.Arrays.Sorting.sortArrayOfComparable
68846900
*/
68856901
public expect fun <T : Comparable<T>> Array<out T>.sort(): Unit
68866902

libraries/stdlib/common/src/generated/_UArrays.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3484,6 +3484,8 @@ public inline operator fun UShortArray.plus(elements: UShortArray): UShortArray
34843484

34853485
/**
34863486
* Sorts the array in-place.
3487+
*
3488+
* @sample samples.collections.Arrays.Sorting.sortArray
34873489
*/
34883490
@SinceKotlin("1.3")
34893491
@ExperimentalUnsignedTypes
@@ -3493,6 +3495,8 @@ public fun UIntArray.sort(): Unit {
34933495

34943496
/**
34953497
* Sorts the array in-place.
3498+
*
3499+
* @sample samples.collections.Arrays.Sorting.sortArray
34963500
*/
34973501
@SinceKotlin("1.3")
34983502
@ExperimentalUnsignedTypes
@@ -3502,6 +3506,8 @@ public fun ULongArray.sort(): Unit {
35023506

35033507
/**
35043508
* Sorts the array in-place.
3509+
*
3510+
* @sample samples.collections.Arrays.Sorting.sortArray
35053511
*/
35063512
@SinceKotlin("1.3")
35073513
@ExperimentalUnsignedTypes
@@ -3511,6 +3517,8 @@ public fun UByteArray.sort(): Unit {
35113517

35123518
/**
35133519
* Sorts the array in-place.
3520+
*
3521+
* @sample samples.collections.Arrays.Sorting.sortArray
35143522
*/
35153523
@SinceKotlin("1.3")
35163524
@ExperimentalUnsignedTypes

libraries/stdlib/js-ir/src/generated/_ArraysJs.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,48 +1403,62 @@ public actual inline fun <T> Array<out T>.plusElement(element: T): Array<T> {
14031403

14041404
/**
14051405
* Sorts the array in-place.
1406+
*
1407+
* @sample samples.collections.Arrays.Sorting.sortArray
14061408
*/
14071409
public actual fun IntArray.sort(): Unit {
14081410
this.asDynamic().sort()
14091411
}
14101412

14111413
/**
14121414
* Sorts the array in-place.
1415+
*
1416+
* @sample samples.collections.Arrays.Sorting.sortArray
14131417
*/
14141418
public actual fun LongArray.sort(): Unit {
14151419
if (size > 1) sort { a: Long, b: Long -> a.compareTo(b) }
14161420
}
14171421

14181422
/**
14191423
* Sorts the array in-place.
1424+
*
1425+
* @sample samples.collections.Arrays.Sorting.sortArray
14201426
*/
14211427
public actual fun ByteArray.sort(): Unit {
14221428
this.asDynamic().sort()
14231429
}
14241430

14251431
/**
14261432
* Sorts the array in-place.
1433+
*
1434+
* @sample samples.collections.Arrays.Sorting.sortArray
14271435
*/
14281436
public actual fun ShortArray.sort(): Unit {
14291437
this.asDynamic().sort()
14301438
}
14311439

14321440
/**
14331441
* Sorts the array in-place.
1442+
*
1443+
* @sample samples.collections.Arrays.Sorting.sortArray
14341444
*/
14351445
public actual fun DoubleArray.sort(): Unit {
14361446
this.asDynamic().sort()
14371447
}
14381448

14391449
/**
14401450
* Sorts the array in-place.
1451+
*
1452+
* @sample samples.collections.Arrays.Sorting.sortArray
14411453
*/
14421454
public actual fun FloatArray.sort(): Unit {
14431455
this.asDynamic().sort()
14441456
}
14451457

14461458
/**
14471459
* Sorts the array in-place.
1460+
*
1461+
* @sample samples.collections.Arrays.Sorting.sortArray
14481462
*/
14491463
public actual fun CharArray.sort(): Unit {
14501464
this.asDynamic().sort(::primitiveCompareTo)
@@ -1454,6 +1468,8 @@ public actual fun CharArray.sort(): Unit {
14541468
* Sorts the array in-place according to the natural order of its elements.
14551469
*
14561470
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
1471+
*
1472+
* @sample samples.collections.Arrays.Sorting.sortArrayOfComparable
14571473
*/
14581474
public actual fun <T : Comparable<T>> Array<out T>.sort(): Unit {
14591475
if (size > 1) sortArray(this)

libraries/stdlib/js/src/generated/_ArraysJs.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,8 @@ public actual inline fun <T> Array<out T>.plusElement(element: T): Array<T> {
14151415

14161416
/**
14171417
* Sorts the array in-place.
1418+
*
1419+
* @sample samples.collections.Arrays.Sorting.sortArray
14181420
*/
14191421
@library("primitiveArraySort")
14201422
public actual fun IntArray.sort(): Unit {
@@ -1423,13 +1425,17 @@ public actual fun IntArray.sort(): Unit {
14231425

14241426
/**
14251427
* Sorts the array in-place.
1428+
*
1429+
* @sample samples.collections.Arrays.Sorting.sortArray
14261430
*/
14271431
public actual fun LongArray.sort(): Unit {
14281432
if (size > 1) sort { a: Long, b: Long -> a.compareTo(b) }
14291433
}
14301434

14311435
/**
14321436
* Sorts the array in-place.
1437+
*
1438+
* @sample samples.collections.Arrays.Sorting.sortArray
14331439
*/
14341440
@library("primitiveArraySort")
14351441
public actual fun ByteArray.sort(): Unit {
@@ -1438,6 +1444,8 @@ public actual fun ByteArray.sort(): Unit {
14381444

14391445
/**
14401446
* Sorts the array in-place.
1447+
*
1448+
* @sample samples.collections.Arrays.Sorting.sortArray
14411449
*/
14421450
@library("primitiveArraySort")
14431451
public actual fun ShortArray.sort(): Unit {
@@ -1446,6 +1454,8 @@ public actual fun ShortArray.sort(): Unit {
14461454

14471455
/**
14481456
* Sorts the array in-place.
1457+
*
1458+
* @sample samples.collections.Arrays.Sorting.sortArray
14491459
*/
14501460
@library("primitiveArraySort")
14511461
public actual fun DoubleArray.sort(): Unit {
@@ -1454,6 +1464,8 @@ public actual fun DoubleArray.sort(): Unit {
14541464

14551465
/**
14561466
* Sorts the array in-place.
1467+
*
1468+
* @sample samples.collections.Arrays.Sorting.sortArray
14571469
*/
14581470
@library("primitiveArraySort")
14591471
public actual fun FloatArray.sort(): Unit {
@@ -1462,6 +1474,8 @@ public actual fun FloatArray.sort(): Unit {
14621474

14631475
/**
14641476
* Sorts the array in-place.
1477+
*
1478+
* @sample samples.collections.Arrays.Sorting.sortArray
14651479
*/
14661480
@library("primitiveArraySort")
14671481
public actual fun CharArray.sort(): Unit {
@@ -1472,6 +1486,8 @@ public actual fun CharArray.sort(): Unit {
14721486
* Sorts the array in-place according to the natural order of its elements.
14731487
*
14741488
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
1489+
*
1490+
* @sample samples.collections.Arrays.Sorting.sortArrayOfComparable
14751491
*/
14761492
public actual fun <T : Comparable<T>> Array<out T>.sort(): Unit {
14771493
if (size > 1) sortArray(this)

libraries/stdlib/jvm/src/generated/_ArraysJvm.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,48 +1791,62 @@ public actual inline fun <T> Array<T>.plusElement(element: T): Array<T> {
17911791

17921792
/**
17931793
* Sorts the array in-place.
1794+
*
1795+
* @sample samples.collections.Arrays.Sorting.sortArray
17941796
*/
17951797
public actual fun IntArray.sort(): Unit {
17961798
if (size > 1) java.util.Arrays.sort(this)
17971799
}
17981800

17991801
/**
18001802
* Sorts the array in-place.
1803+
*
1804+
* @sample samples.collections.Arrays.Sorting.sortArray
18011805
*/
18021806
public actual fun LongArray.sort(): Unit {
18031807
if (size > 1) java.util.Arrays.sort(this)
18041808
}
18051809

18061810
/**
18071811
* Sorts the array in-place.
1812+
*
1813+
* @sample samples.collections.Arrays.Sorting.sortArray
18081814
*/
18091815
public actual fun ByteArray.sort(): Unit {
18101816
if (size > 1) java.util.Arrays.sort(this)
18111817
}
18121818

18131819
/**
18141820
* Sorts the array in-place.
1821+
*
1822+
* @sample samples.collections.Arrays.Sorting.sortArray
18151823
*/
18161824
public actual fun ShortArray.sort(): Unit {
18171825
if (size > 1) java.util.Arrays.sort(this)
18181826
}
18191827

18201828
/**
18211829
* Sorts the array in-place.
1830+
*
1831+
* @sample samples.collections.Arrays.Sorting.sortArray
18221832
*/
18231833
public actual fun DoubleArray.sort(): Unit {
18241834
if (size > 1) java.util.Arrays.sort(this)
18251835
}
18261836

18271837
/**
18281838
* Sorts the array in-place.
1839+
*
1840+
* @sample samples.collections.Arrays.Sorting.sortArray
18291841
*/
18301842
public actual fun FloatArray.sort(): Unit {
18311843
if (size > 1) java.util.Arrays.sort(this)
18321844
}
18331845

18341846
/**
18351847
* Sorts the array in-place.
1848+
*
1849+
* @sample samples.collections.Arrays.Sorting.sortArray
18361850
*/
18371851
public actual fun CharArray.sort(): Unit {
18381852
if (size > 1) java.util.Arrays.sort(this)
@@ -1842,6 +1856,8 @@ public actual fun CharArray.sort(): Unit {
18421856
* Sorts the array in-place according to the natural order of its elements.
18431857
*
18441858
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
1859+
*
1860+
* @sample samples.collections.Arrays.Sorting.sortArrayOfComparable
18451861
*/
18461862
@kotlin.internal.InlineOnly
18471863
public actual inline fun <T : Comparable<T>> Array<out T>.sort(): Unit {
@@ -1864,55 +1880,71 @@ public fun <T> Array<out T>.sort(): Unit {
18641880
* Sorts a range in the array in-place.
18651881
*
18661882
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
1883+
*
1884+
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
18671885
*/
18681886
public fun <T> Array<out T>.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
18691887
java.util.Arrays.sort(this, fromIndex, toIndex)
18701888
}
18711889

18721890
/**
18731891
* Sorts a range in the array in-place.
1892+
*
1893+
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
18741894
*/
18751895
public fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
18761896
java.util.Arrays.sort(this, fromIndex, toIndex)
18771897
}
18781898

18791899
/**
18801900
* Sorts a range in the array in-place.
1901+
*
1902+
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
18811903
*/
18821904
public fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
18831905
java.util.Arrays.sort(this, fromIndex, toIndex)
18841906
}
18851907

18861908
/**
18871909
* Sorts a range in the array in-place.
1910+
*
1911+
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
18881912
*/
18891913
public fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
18901914
java.util.Arrays.sort(this, fromIndex, toIndex)
18911915
}
18921916

18931917
/**
18941918
* Sorts a range in the array in-place.
1919+
*
1920+
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
18951921
*/
18961922
public fun LongArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
18971923
java.util.Arrays.sort(this, fromIndex, toIndex)
18981924
}
18991925

19001926
/**
19011927
* Sorts a range in the array in-place.
1928+
*
1929+
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
19021930
*/
19031931
public fun FloatArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
19041932
java.util.Arrays.sort(this, fromIndex, toIndex)
19051933
}
19061934

19071935
/**
19081936
* Sorts a range in the array in-place.
1937+
*
1938+
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
19091939
*/
19101940
public fun DoubleArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
19111941
java.util.Arrays.sort(this, fromIndex, toIndex)
19121942
}
19131943

19141944
/**
19151945
* Sorts a range in the array in-place.
1946+
*
1947+
* @sample samples.collections.Arrays.Sorting.sortRangeOfComparable
19161948
*/
19171949
public fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit {
19181950
java.util.Arrays.sort(this, fromIndex, toIndex)

libraries/stdlib/jvm/src/kotlin/collections/MutableCollectionsJVM.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public inline fun <T> MutableList<T>.sort(comparison: (T, T) -> Int): Unit = thr
2424
* Sorts elements in the list in-place according to their natural sort order.
2525
*
2626
* The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting.
27+
* @sample samples.collections.Collections.Sorting.sortMutableList
2728
*/
2829
public actual fun <T : Comparable<T>> MutableList<T>.sort(): Unit {
2930
if (size > 1) java.util.Collections.sort(this)

0 commit comments

Comments
 (0)