Implement sorting extension functions for UArrays
This commit is contained in:
committed by
Ilya Gorbunov
parent
c42dbb34ca
commit
cb587893c0
+24
@@ -2395,6 +2395,30 @@ public final class kotlin/collections/UArraysKt {
|
||||
public static final fun sliceArray-ojwP5H8 ([SLjava/util/Collection;)[S
|
||||
public static final fun sliceArray-tAntMlw ([ILkotlin/ranges/IntRange;)[I
|
||||
public static final fun sliceArray-xo_DsdI ([BLjava/util/Collection;)[B
|
||||
public static final fun sort--ajY-9A ([I)V
|
||||
public static final fun sort-GBYM_sE ([B)V
|
||||
public static final fun sort-QwZRm1k ([J)V
|
||||
public static final fun sort-rL5Bavg ([S)V
|
||||
public static final fun sortDescending--ajY-9A ([I)V
|
||||
public static final fun sortDescending-GBYM_sE ([B)V
|
||||
public static final fun sortDescending-QwZRm1k ([J)V
|
||||
public static final fun sortDescending-rL5Bavg ([S)V
|
||||
public static final fun sorted--ajY-9A ([I)Ljava/util/List;
|
||||
public static final fun sorted-GBYM_sE ([B)Ljava/util/List;
|
||||
public static final fun sorted-QwZRm1k ([J)Ljava/util/List;
|
||||
public static final fun sorted-rL5Bavg ([S)Ljava/util/List;
|
||||
public static final fun sortedArray--ajY-9A ([I)[I
|
||||
public static final fun sortedArray-GBYM_sE ([B)[B
|
||||
public static final fun sortedArray-QwZRm1k ([J)[J
|
||||
public static final fun sortedArray-rL5Bavg ([S)[S
|
||||
public static final fun sortedArrayDescending--ajY-9A ([I)[I
|
||||
public static final fun sortedArrayDescending-GBYM_sE ([B)[B
|
||||
public static final fun sortedArrayDescending-QwZRm1k ([J)[J
|
||||
public static final fun sortedArrayDescending-rL5Bavg ([S)[S
|
||||
public static final fun sortedDescending--ajY-9A ([I)Ljava/util/List;
|
||||
public static final fun sortedDescending-GBYM_sE ([B)Ljava/util/List;
|
||||
public static final fun sortedDescending-QwZRm1k ([J)Ljava/util/List;
|
||||
public static final fun sortedDescending-rL5Bavg ([S)Ljava/util/List;
|
||||
public static final fun sumOfUByte ([Lkotlin/UByte;)I
|
||||
public static final fun sumOfUInt ([Lkotlin/UInt;)I
|
||||
public static final fun sumOfULong ([Lkotlin/ULong;)J
|
||||
|
||||
@@ -1010,54 +1010,62 @@ object ArrayOps : TemplateGroupBase() {
|
||||
|
||||
val f_sort = fn("sort()") {
|
||||
include(ArraysOfPrimitives, PrimitiveType.numericPrimitives + PrimitiveType.Char)
|
||||
include(ArraysOfUnsigned)
|
||||
include(ArraysOfObjects)
|
||||
} builder {
|
||||
typeParam("T : Comparable<T>")
|
||||
doc { "Sorts the array in-place according to the natural order of its elements." }
|
||||
appendStableSortNote()
|
||||
specialFor(ArraysOfPrimitives) {
|
||||
specialFor(ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
doc { "Sorts the array in-place." }
|
||||
}
|
||||
|
||||
returns("Unit")
|
||||
on(Platform.JS) {
|
||||
body {
|
||||
"""if (size > 1) sortArray(this)"""
|
||||
|
||||
body(ArraysOfUnsigned) {
|
||||
"""if (size > 1) sortArray(this)"""
|
||||
}
|
||||
|
||||
specialFor(ArraysOfPrimitives, ArraysOfObjects) {
|
||||
on(Platform.JS) {
|
||||
body {
|
||||
"""if (size > 1) sortArray(this)"""
|
||||
}
|
||||
specialFor(ArraysOfPrimitives) {
|
||||
if (primitive != PrimitiveType.Long) {
|
||||
on(Backend.Legacy) {
|
||||
annotation("""@library("primitiveArraySort")""")
|
||||
body { "definedExternally" }
|
||||
}
|
||||
on(Backend.IR) {
|
||||
body { "this.asDynamic().sort()" }
|
||||
}
|
||||
} else {
|
||||
body {
|
||||
"""if (size > 1) sort { a: T, b: T -> a.compareTo(b) }"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
specialFor(ArraysOfPrimitives) {
|
||||
if (primitive != PrimitiveType.Long) {
|
||||
on(Backend.Legacy) {
|
||||
annotation("""@library("primitiveArraySort")""")
|
||||
body { "definedExternally" }
|
||||
}
|
||||
on(Backend.IR) {
|
||||
body { "this.asDynamic().sort()" }
|
||||
}
|
||||
} else {
|
||||
on(Platform.JVM) {
|
||||
specialFor(ArraysOfObjects) {
|
||||
inlineOnly()
|
||||
body {
|
||||
"""if (size > 1) sort { a: T, b: T -> a.compareTo(b) }"""
|
||||
"""
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(this as Array<Any?>).sort()
|
||||
"""
|
||||
}
|
||||
}
|
||||
specialFor(ArraysOfPrimitives) {
|
||||
body {
|
||||
"if (size > 1) java.util.Arrays.sort(this)"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
on(Platform.JVM) {
|
||||
specialFor(ArraysOfObjects) {
|
||||
inlineOnly()
|
||||
body {
|
||||
"""
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(this as Array<Any?>).sort()
|
||||
"""
|
||||
}
|
||||
on(Platform.Native) {
|
||||
body { """if (size > 1) sortArray(this)""" }
|
||||
}
|
||||
specialFor(ArraysOfPrimitives) {
|
||||
body {
|
||||
"if (size > 1) java.util.Arrays.sort(this)"
|
||||
}
|
||||
}
|
||||
}
|
||||
on(Platform.Native) {
|
||||
body { """if (size > 1) sortArray(this)""" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ object Ordering : TemplateGroupBase() {
|
||||
val f_sorted = fn("sorted()") {
|
||||
includeDefault()
|
||||
exclude(PrimitiveType.Boolean)
|
||||
include(ArraysOfUnsigned)
|
||||
} builder {
|
||||
|
||||
doc {
|
||||
@@ -140,7 +141,7 @@ object Ordering : TemplateGroupBase() {
|
||||
Returns a list of all elements sorted according to their natural sort order.
|
||||
"""
|
||||
}
|
||||
if (f != ArraysOfPrimitives) {
|
||||
if (f != ArraysOfPrimitives && f != ArraysOfUnsigned) {
|
||||
appendStableSortNote()
|
||||
}
|
||||
returns("List<T>")
|
||||
@@ -160,6 +161,11 @@ object Ordering : TemplateGroupBase() {
|
||||
return toTypedArray().apply { sort() }.asList()
|
||||
"""
|
||||
}
|
||||
body(ArraysOfUnsigned) {
|
||||
"""
|
||||
return copyOf().apply { sort() }.asList()
|
||||
"""
|
||||
}
|
||||
body(ArraysOfObjects) {
|
||||
"""
|
||||
return sortedArray().asList()
|
||||
@@ -188,7 +194,7 @@ object Ordering : TemplateGroupBase() {
|
||||
}
|
||||
|
||||
val f_sortedArray = fn("sortedArray()") {
|
||||
include(InvariantArraysOfObjects, ArraysOfPrimitives)
|
||||
include(InvariantArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
exclude(PrimitiveType.Boolean)
|
||||
} builder {
|
||||
doc {
|
||||
@@ -208,11 +214,11 @@ object Ordering : TemplateGroupBase() {
|
||||
}
|
||||
|
||||
val f_sortDescending = fn("sortDescending()") {
|
||||
include(Lists, ArraysOfObjects, ArraysOfPrimitives)
|
||||
include(Lists, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
exclude(PrimitiveType.Boolean)
|
||||
} builder {
|
||||
doc { """Sorts elements in the ${f.collection} in-place descending according to their natural sort order.""" }
|
||||
if (f != ArraysOfPrimitives) {
|
||||
if (f != ArraysOfPrimitives && f != ArraysOfUnsigned) {
|
||||
appendStableSortNote()
|
||||
}
|
||||
returns("Unit")
|
||||
@@ -222,7 +228,7 @@ object Ordering : TemplateGroupBase() {
|
||||
}
|
||||
|
||||
body { """sortWith(reverseOrder())""" }
|
||||
body(ArraysOfPrimitives) {
|
||||
body(ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
"""
|
||||
if (size > 1) {
|
||||
sort()
|
||||
@@ -235,6 +241,7 @@ object Ordering : TemplateGroupBase() {
|
||||
val f_sortedDescending = fn("sortedDescending()") {
|
||||
includeDefault()
|
||||
exclude(PrimitiveType.Boolean)
|
||||
include(ArraysOfUnsigned)
|
||||
} builder {
|
||||
|
||||
doc {
|
||||
@@ -252,7 +259,7 @@ object Ordering : TemplateGroupBase() {
|
||||
return sortedWith(reverseOrder())
|
||||
"""
|
||||
}
|
||||
body(ArraysOfPrimitives) {
|
||||
body(ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
"""
|
||||
return copyOf().apply { sort() }.reversed()
|
||||
"""
|
||||
@@ -269,7 +276,7 @@ object Ordering : TemplateGroupBase() {
|
||||
}
|
||||
|
||||
val f_sortedArrayDescending = fn("sortedArrayDescending()") {
|
||||
include(InvariantArraysOfObjects, ArraysOfPrimitives)
|
||||
include(InvariantArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned)
|
||||
exclude(PrimitiveType.Boolean)
|
||||
} builder {
|
||||
doc {
|
||||
@@ -286,7 +293,7 @@ object Ordering : TemplateGroupBase() {
|
||||
return this.copyOf().apply { sortWith(reverseOrder()) }
|
||||
"""
|
||||
}
|
||||
body(ArraysOfPrimitives) {
|
||||
body(ArraysOfPrimitives, ArraysOfUnsigned) {
|
||||
"""
|
||||
if (isEmpty()) return this
|
||||
return this.copyOf().apply { sortDescending() }
|
||||
|
||||
Reference in New Issue
Block a user