In-place array sorting in JS.

This commit is contained in:
Ilya Gorbunov
2015-07-25 01:31:52 +03:00
parent 8d481fc611
commit 6f71e54268
6 changed files with 181 additions and 9 deletions
@@ -68,6 +68,7 @@ fun toPrimitiveArrays(): List<GenericFunction> =
doc(ArraysOfObjects) { "Returns an array of ${primitive.name} containing all of the elements of this generic array." }
doc(Collections) { "Returns an array of ${primitive.name} containing all of the elements of this collection." }
returns(arrayType)
// TODO: Use different implementations for JS
body {
"""
val result = $arrayType(size())
@@ -131,6 +131,37 @@ fun specialJS(): List<GenericFunction> {
}
}
templates add f("sort(comparison: (T, T) -> Int)") {
only(ArraysOfObjects, ArraysOfPrimitives)
exclude(PrimitiveType.Boolean)
annotations("native")
returns("Unit")
doc { "Sorts the array inplace according to the order specified by the given [comparison] function." }
body { "return noImpl" }
}
templates add f("sort()") {
only(ArraysOfPrimitives)
only(numericPrimitives + PrimitiveType.Char)
exclude(PrimitiveType.Long)
returns("Unit")
doc { "Sorts the array inplace." }
annotations("""library("primitiveArraySort")""")
body { "return noImpl" }
}
templates add f("sort()") {
only(ArraysOfObjects, ArraysOfPrimitives)
only(PrimitiveType.Long)
typeParam("T: Comparable<T>")
returns("Unit")
doc { "Sorts the array inplace." }
body {
"""
sort { a: T, b: T -> a.compareTo(b) }
"""
}
}
return templates