/* * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the license/LICENSE.txt file. */ package kotlin.collections // // NOTE: THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt // See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib // import kotlin.js.* import primitiveArrayConcat import withType /** * Returns a [List] that wraps the original array. */ public actual fun Array.asList(): List { return ArrayList(this.unsafeCast>()) } /** * Returns a [List] that wraps the original array. */ @kotlin.internal.InlineOnly public actual inline fun ByteArray.asList(): List { return this.unsafeCast>().asList() } /** * Returns a [List] that wraps the original array. */ @kotlin.internal.InlineOnly public actual inline fun ShortArray.asList(): List { return this.unsafeCast>().asList() } /** * Returns a [List] that wraps the original array. */ @kotlin.internal.InlineOnly public actual inline fun IntArray.asList(): List { return this.unsafeCast>().asList() } /** * Returns a [List] that wraps the original array. */ @kotlin.internal.InlineOnly public actual inline fun LongArray.asList(): List { return this.unsafeCast>().asList() } /** * Returns a [List] that wraps the original array. */ @kotlin.internal.InlineOnly public actual inline fun FloatArray.asList(): List { return this.unsafeCast>().asList() } /** * Returns a [List] that wraps the original array. */ @kotlin.internal.InlineOnly public actual inline fun DoubleArray.asList(): List { return this.unsafeCast>().asList() } /** * Returns a [List] that wraps the original array. */ @kotlin.internal.InlineOnly public actual inline fun BooleanArray.asList(): List { return this.unsafeCast>().asList() } /** * Returns a [List] that wraps the original array. */ public actual fun CharArray.asList(): List { return object : AbstractList(), RandomAccess { override val size: Int get() = this@asList.size override fun isEmpty(): Boolean = this@asList.isEmpty() override fun contains(element: Char): Boolean = this@asList.contains(element) override fun get(index: Int): Char = this@asList[index] override fun indexOf(element: Char): Int = this@asList.indexOf(element) override fun lastIndexOf(element: Char): Int = this@asList.lastIndexOf(element) } } /** * Returns `true` if the two specified arrays are *deeply* equal to one another, * i.e. contain the same number of the same elements in the same order. * * If two corresponding elements are nested arrays, they are also compared deeply. * If any of arrays contains itself on any nesting level the behavior is undefined. * * The elements of other types are compared for equality with the [equals][Any.equals] function. * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun Array.contentDeepEquals(other: Array): Boolean { return contentDeepEqualsImpl(other) } /** * Returns a hash code based on the contents of this array as if it is [List]. * Nested arrays are treated as lists too. * * If any of arrays contains itself on any nesting level the behavior is undefined. */ @SinceKotlin("1.1") public actual fun Array.contentDeepHashCode(): Int { return contentDeepHashCodeInternal() } /** * Returns a string representation of the contents of this array as if it is a [List]. * Nested arrays are treated as lists too. * * If any of arrays contains itself on any nesting level that reference * is rendered as `"[...]"` to prevent recursion. * * @sample samples.collections.Arrays.ContentOperations.contentDeepToString */ @SinceKotlin("1.1") public actual fun Array.contentDeepToString(): String { return contentDeepToStringImpl() } /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. * * The elements are compared for equality with the [equals][Any.equals] function. * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun Array.contentEquals(other: Array): Boolean { return contentEqualsInternal(other) } /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. * * The elements are compared for equality with the [equals][Any.equals] function. * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean { return contentEqualsInternal(other) } /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. * * The elements are compared for equality with the [equals][Any.equals] function. * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean { return contentEqualsInternal(other) } /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. * * The elements are compared for equality with the [equals][Any.equals] function. * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun IntArray.contentEquals(other: IntArray): Boolean { return contentEqualsInternal(other) } /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. * * The elements are compared for equality with the [equals][Any.equals] function. * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun LongArray.contentEquals(other: LongArray): Boolean { return contentEqualsInternal(other) } /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. * * The elements are compared for equality with the [equals][Any.equals] function. * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean { return contentEqualsInternal(other) } /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. * * The elements are compared for equality with the [equals][Any.equals] function. * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean { return contentEqualsInternal(other) } /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. * * The elements are compared for equality with the [equals][Any.equals] function. * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean { return contentEqualsInternal(other) } /** * Returns `true` if the two specified arrays are *structurally* equal to one another, * i.e. contain the same number of the same elements in the same order. * * The elements are compared for equality with the [equals][Any.equals] function. * For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`. */ @SinceKotlin("1.1") public actual infix fun CharArray.contentEquals(other: CharArray): Boolean { return contentEqualsInternal(other) } /** * Returns a hash code based on the contents of this array as if it is [List]. */ @SinceKotlin("1.1") public actual fun Array.contentHashCode(): Int { return contentHashCodeInternal() } /** * Returns a hash code based on the contents of this array as if it is [List]. */ @SinceKotlin("1.1") public actual fun ByteArray.contentHashCode(): Int { return contentHashCodeInternal() } /** * Returns a hash code based on the contents of this array as if it is [List]. */ @SinceKotlin("1.1") public actual fun ShortArray.contentHashCode(): Int { return contentHashCodeInternal() } /** * Returns a hash code based on the contents of this array as if it is [List]. */ @SinceKotlin("1.1") public actual fun IntArray.contentHashCode(): Int { return contentHashCodeInternal() } /** * Returns a hash code based on the contents of this array as if it is [List]. */ @SinceKotlin("1.1") public actual fun LongArray.contentHashCode(): Int { return contentHashCodeInternal() } /** * Returns a hash code based on the contents of this array as if it is [List]. */ @SinceKotlin("1.1") public actual fun FloatArray.contentHashCode(): Int { return contentHashCodeInternal() } /** * Returns a hash code based on the contents of this array as if it is [List]. */ @SinceKotlin("1.1") public actual fun DoubleArray.contentHashCode(): Int { return contentHashCodeInternal() } /** * Returns a hash code based on the contents of this array as if it is [List]. */ @SinceKotlin("1.1") public actual fun BooleanArray.contentHashCode(): Int { return contentHashCodeInternal() } /** * Returns a hash code based on the contents of this array as if it is [List]. */ @SinceKotlin("1.1") public actual fun CharArray.contentHashCode(): Int { return contentHashCodeInternal() } /** * Returns a string representation of the contents of the specified array as if it is [List]. * * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public actual fun Array.contentToString(): String { return arrayToString(this as Array<*>) } /** * Returns a string representation of the contents of the specified array as if it is [List]. * * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public actual fun ByteArray.contentToString(): String { return arrayToString(this as Array<*>) } /** * Returns a string representation of the contents of the specified array as if it is [List]. * * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public actual fun ShortArray.contentToString(): String { return arrayToString(this as Array<*>) } /** * Returns a string representation of the contents of the specified array as if it is [List]. * * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public actual fun IntArray.contentToString(): String { return arrayToString(this as Array<*>) } /** * Returns a string representation of the contents of the specified array as if it is [List]. * * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public actual fun LongArray.contentToString(): String { return arrayToString(this as Array<*>) } /** * Returns a string representation of the contents of the specified array as if it is [List]. * * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public actual fun FloatArray.contentToString(): String { return arrayToString(this as Array<*>) } /** * Returns a string representation of the contents of the specified array as if it is [List]. * * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public actual fun DoubleArray.contentToString(): String { return arrayToString(this as Array<*>) } /** * Returns a string representation of the contents of the specified array as if it is [List]. * * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public actual fun BooleanArray.contentToString(): String { return arrayToString(this as Array<*>) } /** * Returns a string representation of the contents of the specified array as if it is [List]. * * @sample samples.collections.Arrays.ContentOperations.contentToString */ @SinceKotlin("1.1") public actual fun CharArray.contentToString(): String { return arrayToString(this as Array<*>) } /** * Copies this array or its subrange into the [destination] array and returns that array. * * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. * * @param destination the array to copy to. * @param destinationOffset the position in the [destination] array to copy to, 0 by default. * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. * * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], * or when that index is out of the [destination] array indices range. * * @return the [destination] array. */ @SinceKotlin("1.3") @kotlin.internal.InlineOnly @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual inline fun Array.copyInto(destination: Array, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): Array { arrayCopy(this, destination, destinationOffset, startIndex, endIndex) return destination } /** * Copies this array or its subrange into the [destination] array and returns that array. * * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. * * @param destination the array to copy to. * @param destinationOffset the position in the [destination] array to copy to, 0 by default. * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. * * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], * or when that index is out of the [destination] array indices range. * * @return the [destination] array. */ @SinceKotlin("1.3") @kotlin.internal.InlineOnly @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual inline fun ByteArray.copyInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): ByteArray { arrayCopy(this.unsafeCast>(), destination.unsafeCast>(), destinationOffset, startIndex, endIndex) return destination } /** * Copies this array or its subrange into the [destination] array and returns that array. * * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. * * @param destination the array to copy to. * @param destinationOffset the position in the [destination] array to copy to, 0 by default. * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. * * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], * or when that index is out of the [destination] array indices range. * * @return the [destination] array. */ @SinceKotlin("1.3") @kotlin.internal.InlineOnly @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual inline fun ShortArray.copyInto(destination: ShortArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): ShortArray { arrayCopy(this.unsafeCast>(), destination.unsafeCast>(), destinationOffset, startIndex, endIndex) return destination } /** * Copies this array or its subrange into the [destination] array and returns that array. * * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. * * @param destination the array to copy to. * @param destinationOffset the position in the [destination] array to copy to, 0 by default. * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. * * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], * or when that index is out of the [destination] array indices range. * * @return the [destination] array. */ @SinceKotlin("1.3") @kotlin.internal.InlineOnly @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual inline fun IntArray.copyInto(destination: IntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): IntArray { arrayCopy(this.unsafeCast>(), destination.unsafeCast>(), destinationOffset, startIndex, endIndex) return destination } /** * Copies this array or its subrange into the [destination] array and returns that array. * * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. * * @param destination the array to copy to. * @param destinationOffset the position in the [destination] array to copy to, 0 by default. * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. * * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], * or when that index is out of the [destination] array indices range. * * @return the [destination] array. */ @SinceKotlin("1.3") @kotlin.internal.InlineOnly @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual inline fun LongArray.copyInto(destination: LongArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): LongArray { arrayCopy(this.unsafeCast>(), destination.unsafeCast>(), destinationOffset, startIndex, endIndex) return destination } /** * Copies this array or its subrange into the [destination] array and returns that array. * * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. * * @param destination the array to copy to. * @param destinationOffset the position in the [destination] array to copy to, 0 by default. * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. * * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], * or when that index is out of the [destination] array indices range. * * @return the [destination] array. */ @SinceKotlin("1.3") @kotlin.internal.InlineOnly @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual inline fun FloatArray.copyInto(destination: FloatArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): FloatArray { arrayCopy(this.unsafeCast>(), destination.unsafeCast>(), destinationOffset, startIndex, endIndex) return destination } /** * Copies this array or its subrange into the [destination] array and returns that array. * * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. * * @param destination the array to copy to. * @param destinationOffset the position in the [destination] array to copy to, 0 by default. * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. * * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], * or when that index is out of the [destination] array indices range. * * @return the [destination] array. */ @SinceKotlin("1.3") @kotlin.internal.InlineOnly @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual inline fun DoubleArray.copyInto(destination: DoubleArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): DoubleArray { arrayCopy(this.unsafeCast>(), destination.unsafeCast>(), destinationOffset, startIndex, endIndex) return destination } /** * Copies this array or its subrange into the [destination] array and returns that array. * * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. * * @param destination the array to copy to. * @param destinationOffset the position in the [destination] array to copy to, 0 by default. * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. * * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], * or when that index is out of the [destination] array indices range. * * @return the [destination] array. */ @SinceKotlin("1.3") @kotlin.internal.InlineOnly @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual inline fun BooleanArray.copyInto(destination: BooleanArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): BooleanArray { arrayCopy(this.unsafeCast>(), destination.unsafeCast>(), destinationOffset, startIndex, endIndex) return destination } /** * Copies this array or its subrange into the [destination] array and returns that array. * * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. * * @param destination the array to copy to. * @param destinationOffset the position in the [destination] array to copy to, 0 by default. * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. * * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], * or when that index is out of the [destination] array indices range. * * @return the [destination] array. */ @SinceKotlin("1.3") @kotlin.internal.InlineOnly @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual inline fun CharArray.copyInto(destination: CharArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): CharArray { arrayCopy(this.unsafeCast>(), destination.unsafeCast>(), destinationOffset, startIndex, endIndex) return destination } /** * Returns new array which is a copy of the original array. * * @sample samples.collections.Arrays.CopyOfOperations.copyOf */ @Suppress("ACTUAL_WITHOUT_EXPECT", "NOTHING_TO_INLINE") public actual inline fun Array.copyOf(): Array { return this.asDynamic().slice() } /** * Returns new array which is a copy of the original array. * * @sample samples.collections.Arrays.CopyOfOperations.copyOf */ @Suppress("NOTHING_TO_INLINE") public actual inline fun ByteArray.copyOf(): ByteArray { return this.asDynamic().slice() } /** * Returns new array which is a copy of the original array. * * @sample samples.collections.Arrays.CopyOfOperations.copyOf */ @Suppress("NOTHING_TO_INLINE") public actual inline fun ShortArray.copyOf(): ShortArray { return this.asDynamic().slice() } /** * Returns new array which is a copy of the original array. * * @sample samples.collections.Arrays.CopyOfOperations.copyOf */ @Suppress("NOTHING_TO_INLINE") public actual inline fun IntArray.copyOf(): IntArray { return this.asDynamic().slice() } /** * Returns new array which is a copy of the original array. * * @sample samples.collections.Arrays.CopyOfOperations.copyOf */ public actual fun LongArray.copyOf(): LongArray { return withType("LongArray", this.asDynamic().slice()) } /** * Returns new array which is a copy of the original array. * * @sample samples.collections.Arrays.CopyOfOperations.copyOf */ @Suppress("NOTHING_TO_INLINE") public actual inline fun FloatArray.copyOf(): FloatArray { return this.asDynamic().slice() } /** * Returns new array which is a copy of the original array. * * @sample samples.collections.Arrays.CopyOfOperations.copyOf */ @Suppress("NOTHING_TO_INLINE") public actual inline fun DoubleArray.copyOf(): DoubleArray { return this.asDynamic().slice() } /** * Returns new array which is a copy of the original array. * * @sample samples.collections.Arrays.CopyOfOperations.copyOf */ public actual fun BooleanArray.copyOf(): BooleanArray { return withType("BooleanArray", this.asDynamic().slice()) } /** * Returns new array which is a copy of the original array. * * @sample samples.collections.Arrays.CopyOfOperations.copyOf */ public actual fun CharArray.copyOf(): CharArray { return withType("CharArray", this.asDynamic().slice()) } /** * Returns new array which is a copy of the original array, resized to the given [newSize]. * The copy is either truncated or padded at the end with zero values if necessary. * * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. * * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf */ public actual fun ByteArray.copyOf(newSize: Int): ByteArray { require(newSize >= 0) { "Invalid new array size: $newSize." } return fillFrom(this, ByteArray(newSize)) } /** * Returns new array which is a copy of the original array, resized to the given [newSize]. * The copy is either truncated or padded at the end with zero values if necessary. * * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. * * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf */ public actual fun ShortArray.copyOf(newSize: Int): ShortArray { require(newSize >= 0) { "Invalid new array size: $newSize." } return fillFrom(this, ShortArray(newSize)) } /** * Returns new array which is a copy of the original array, resized to the given [newSize]. * The copy is either truncated or padded at the end with zero values if necessary. * * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. * * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf */ public actual fun IntArray.copyOf(newSize: Int): IntArray { require(newSize >= 0) { "Invalid new array size: $newSize." } return fillFrom(this, IntArray(newSize)) } /** * Returns new array which is a copy of the original array, resized to the given [newSize]. * The copy is either truncated or padded at the end with zero values if necessary. * * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. * * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf */ public actual fun LongArray.copyOf(newSize: Int): LongArray { require(newSize >= 0) { "Invalid new array size: $newSize." } return withType("LongArray", arrayCopyResize(this, newSize, 0L)) } /** * Returns new array which is a copy of the original array, resized to the given [newSize]. * The copy is either truncated or padded at the end with zero values if necessary. * * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. * * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf */ public actual fun FloatArray.copyOf(newSize: Int): FloatArray { require(newSize >= 0) { "Invalid new array size: $newSize." } return fillFrom(this, FloatArray(newSize)) } /** * Returns new array which is a copy of the original array, resized to the given [newSize]. * The copy is either truncated or padded at the end with zero values if necessary. * * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. * * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf */ public actual fun DoubleArray.copyOf(newSize: Int): DoubleArray { require(newSize >= 0) { "Invalid new array size: $newSize." } return fillFrom(this, DoubleArray(newSize)) } /** * Returns new array which is a copy of the original array, resized to the given [newSize]. * The copy is either truncated or padded at the end with `false` values if necessary. * * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with `false` values. * * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf */ public actual fun BooleanArray.copyOf(newSize: Int): BooleanArray { require(newSize >= 0) { "Invalid new array size: $newSize." } return withType("BooleanArray", arrayCopyResize(this, newSize, false)) } /** * Returns new array which is a copy of the original array, resized to the given [newSize]. * The copy is either truncated or padded at the end with null char (`\u0000`) values if necessary. * * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with null char (`\u0000`) values. * * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf */ public actual fun CharArray.copyOf(newSize: Int): CharArray { require(newSize >= 0) { "Invalid new array size: $newSize." } return withType("CharArray", fillFrom(this, CharArray(newSize))) } /** * Returns new array which is a copy of the original array, resized to the given [newSize]. * The copy is either truncated or padded at the end with `null` values if necessary. * * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with `null` values. * * @sample samples.collections.Arrays.CopyOfOperations.resizingCopyOf */ @Suppress("ACTUAL_WITHOUT_EXPECT") public actual fun Array.copyOf(newSize: Int): Array { require(newSize >= 0) { "Invalid new array size: $newSize." } return arrayCopyResize(this, newSize, null) } /** * Returns a new array which is a copy of the specified range of the original array. * * @param fromIndex the start of the range (inclusive), must be in `0..array.size` * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` */ @Suppress("ACTUAL_WITHOUT_EXPECT") public actual fun Array.copyOfRange(fromIndex: Int, toIndex: Int): Array { AbstractList.checkRangeIndexes(fromIndex, toIndex, size) return this.asDynamic().slice(fromIndex, toIndex) } /** * Returns a new array which is a copy of the specified range of the original array. * * @param fromIndex the start of the range (inclusive), must be in `0..array.size` * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` */ public actual fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray { AbstractList.checkRangeIndexes(fromIndex, toIndex, size) return this.asDynamic().slice(fromIndex, toIndex) } /** * Returns a new array which is a copy of the specified range of the original array. * * @param fromIndex the start of the range (inclusive), must be in `0..array.size` * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` */ public actual fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray { AbstractList.checkRangeIndexes(fromIndex, toIndex, size) return this.asDynamic().slice(fromIndex, toIndex) } /** * Returns a new array which is a copy of the specified range of the original array. * * @param fromIndex the start of the range (inclusive), must be in `0..array.size` * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` */ public actual fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray { AbstractList.checkRangeIndexes(fromIndex, toIndex, size) return this.asDynamic().slice(fromIndex, toIndex) } /** * Returns a new array which is a copy of the specified range of the original array. * * @param fromIndex the start of the range (inclusive), must be in `0..array.size` * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` */ public actual fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray { AbstractList.checkRangeIndexes(fromIndex, toIndex, size) return withType("LongArray", this.asDynamic().slice(fromIndex, toIndex)) } /** * Returns a new array which is a copy of the specified range of the original array. * * @param fromIndex the start of the range (inclusive), must be in `0..array.size` * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` */ public actual fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray { AbstractList.checkRangeIndexes(fromIndex, toIndex, size) return this.asDynamic().slice(fromIndex, toIndex) } /** * Returns a new array which is a copy of the specified range of the original array. * * @param fromIndex the start of the range (inclusive), must be in `0..array.size` * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` */ public actual fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray { AbstractList.checkRangeIndexes(fromIndex, toIndex, size) return this.asDynamic().slice(fromIndex, toIndex) } /** * Returns a new array which is a copy of the specified range of the original array. * * @param fromIndex the start of the range (inclusive), must be in `0..array.size` * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` */ public actual fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray { AbstractList.checkRangeIndexes(fromIndex, toIndex, size) return withType("BooleanArray", this.asDynamic().slice(fromIndex, toIndex)) } /** * Returns a new array which is a copy of the specified range of the original array. * * @param fromIndex the start of the range (inclusive), must be in `0..array.size` * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` */ public actual fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray { AbstractList.checkRangeIndexes(fromIndex, toIndex, size) return withType("CharArray", this.asDynamic().slice(fromIndex, toIndex)) } /** * Returns an array containing all elements of the original array and then the given [element]. */ @Suppress("ACTUAL_WITHOUT_EXPECT", "NOTHING_TO_INLINE") public actual inline operator fun Array.plus(element: T): Array { return this.asDynamic().concat(arrayOf(element)) } /** * Returns an array containing all elements of the original array and then the given [element]. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun ByteArray.plus(element: Byte): ByteArray { return plus(byteArrayOf(element)) } /** * Returns an array containing all elements of the original array and then the given [element]. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun ShortArray.plus(element: Short): ShortArray { return plus(shortArrayOf(element)) } /** * Returns an array containing all elements of the original array and then the given [element]. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun IntArray.plus(element: Int): IntArray { return plus(intArrayOf(element)) } /** * Returns an array containing all elements of the original array and then the given [element]. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun LongArray.plus(element: Long): LongArray { return plus(longArrayOf(element)) } /** * Returns an array containing all elements of the original array and then the given [element]. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun FloatArray.plus(element: Float): FloatArray { return plus(floatArrayOf(element)) } /** * Returns an array containing all elements of the original array and then the given [element]. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun DoubleArray.plus(element: Double): DoubleArray { return plus(doubleArrayOf(element)) } /** * Returns an array containing all elements of the original array and then the given [element]. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun BooleanArray.plus(element: Boolean): BooleanArray { return plus(booleanArrayOf(element)) } /** * Returns an array containing all elements of the original array and then the given [element]. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun CharArray.plus(element: Char): CharArray { return plus(charArrayOf(element)) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. */ @Suppress("ACTUAL_WITHOUT_EXPECT") public actual operator fun Array.plus(elements: Collection): Array { return arrayPlusCollection(this, elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. */ public actual operator fun ByteArray.plus(elements: Collection): ByteArray { var index = size val result = this.copyOf(size + elements.size) for (element in elements) result[index++] = element return result } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. */ public actual operator fun ShortArray.plus(elements: Collection): ShortArray { var index = size val result = this.copyOf(size + elements.size) for (element in elements) result[index++] = element return result } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. */ public actual operator fun IntArray.plus(elements: Collection): IntArray { var index = size val result = this.copyOf(size + elements.size) for (element in elements) result[index++] = element return result } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. */ public actual operator fun LongArray.plus(elements: Collection): LongArray { return arrayPlusCollection(this, elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. */ public actual operator fun FloatArray.plus(elements: Collection): FloatArray { var index = size val result = this.copyOf(size + elements.size) for (element in elements) result[index++] = element return result } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. */ public actual operator fun DoubleArray.plus(elements: Collection): DoubleArray { var index = size val result = this.copyOf(size + elements.size) for (element in elements) result[index++] = element return result } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. */ public actual operator fun BooleanArray.plus(elements: Collection): BooleanArray { return arrayPlusCollection(this, elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. */ public actual operator fun CharArray.plus(elements: Collection): CharArray { var index = size val result = this.copyOf(size + elements.size) for (element in elements) result[index++] = element return result } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] array. */ @Suppress("ACTUAL_WITHOUT_EXPECT", "NOTHING_TO_INLINE") public actual inline operator fun Array.plus(elements: Array): Array { return this.asDynamic().concat(elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] array. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun ByteArray.plus(elements: ByteArray): ByteArray { return primitiveArrayConcat(this, elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] array. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun ShortArray.plus(elements: ShortArray): ShortArray { return primitiveArrayConcat(this, elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] array. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun IntArray.plus(elements: IntArray): IntArray { return primitiveArrayConcat(this, elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] array. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun LongArray.plus(elements: LongArray): LongArray { return primitiveArrayConcat(this, elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] array. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun FloatArray.plus(elements: FloatArray): FloatArray { return primitiveArrayConcat(this, elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] array. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun DoubleArray.plus(elements: DoubleArray): DoubleArray { return primitiveArrayConcat(this, elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] array. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun BooleanArray.plus(elements: BooleanArray): BooleanArray { return primitiveArrayConcat(this, elements) } /** * Returns an array containing all elements of the original array and then all elements of the given [elements] array. */ @Suppress("NOTHING_TO_INLINE") public actual inline operator fun CharArray.plus(elements: CharArray): CharArray { return primitiveArrayConcat(this, elements) } /** * Returns an array containing all elements of the original array and then the given [element]. */ @Suppress("ACTUAL_WITHOUT_EXPECT", "NOTHING_TO_INLINE") public actual inline fun Array.plusElement(element: T): Array { return this.asDynamic().concat(arrayOf(element)) } /** * Sorts the array in-place. */ public actual fun IntArray.sort(): Unit { this.asDynamic().sort() } /** * Sorts the array in-place. */ public actual fun LongArray.sort(): Unit { if (size > 1) sort { a: Long, b: Long -> a.compareTo(b) } } /** * Sorts the array in-place. */ public actual fun ByteArray.sort(): Unit { this.asDynamic().sort() } /** * Sorts the array in-place. */ public actual fun ShortArray.sort(): Unit { this.asDynamic().sort() } /** * Sorts the array in-place. */ public actual fun DoubleArray.sort(): Unit { this.asDynamic().sort() } /** * Sorts the array in-place. */ public actual fun FloatArray.sort(): Unit { this.asDynamic().sort() } /** * Sorts the array in-place. */ public actual fun CharArray.sort(): Unit { this.asDynamic().sort() } /** * 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. */ public actual fun > Array.sort(): Unit { if (size > 1) sortArray(this) } /** * Sorts the array in-place according to the order specified by the given [comparison] function. * * The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting. */ public fun Array.sort(comparison: (a: T, b: T) -> Int): Unit { if (size > 1) sortArrayWith(this, comparison) } /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ @kotlin.internal.InlineOnly public inline fun ByteArray.sort(noinline comparison: (a: Byte, b: Byte) -> Int): Unit { asDynamic().sort(comparison) } /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ @kotlin.internal.InlineOnly public inline fun ShortArray.sort(noinline comparison: (a: Short, b: Short) -> Int): Unit { asDynamic().sort(comparison) } /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ @kotlin.internal.InlineOnly public inline fun IntArray.sort(noinline comparison: (a: Int, b: Int) -> Int): Unit { asDynamic().sort(comparison) } /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ @kotlin.internal.InlineOnly public inline fun LongArray.sort(noinline comparison: (a: Long, b: Long) -> Int): Unit { asDynamic().sort(comparison) } /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ @kotlin.internal.InlineOnly public inline fun FloatArray.sort(noinline comparison: (a: Float, b: Float) -> Int): Unit { asDynamic().sort(comparison) } /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ @kotlin.internal.InlineOnly public inline fun DoubleArray.sort(noinline comparison: (a: Double, b: Double) -> Int): Unit { asDynamic().sort(comparison) } /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ @kotlin.internal.InlineOnly public inline fun CharArray.sort(noinline comparison: (a: Char, b: Char) -> Int): Unit { asDynamic().sort(comparison) } /** * Sorts the array in-place according to the order specified by the given [comparator]. * * The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting. */ public actual fun Array.sortWith(comparator: Comparator): Unit { if (size > 1) sortArrayWith(this, comparator) } /** * Returns a *typed* object array containing all of the elements of this primitive array. */ public actual fun ByteArray.toTypedArray(): Array { return js("[]").slice.call(this) } /** * Returns a *typed* object array containing all of the elements of this primitive array. */ public actual fun ShortArray.toTypedArray(): Array { return js("[]").slice.call(this) } /** * Returns a *typed* object array containing all of the elements of this primitive array. */ public actual fun IntArray.toTypedArray(): Array { return js("[]").slice.call(this) } /** * Returns a *typed* object array containing all of the elements of this primitive array. */ public actual fun LongArray.toTypedArray(): Array { return js("[]").slice.call(this) } /** * Returns a *typed* object array containing all of the elements of this primitive array. */ public actual fun FloatArray.toTypedArray(): Array { return js("[]").slice.call(this) } /** * Returns a *typed* object array containing all of the elements of this primitive array. */ public actual fun DoubleArray.toTypedArray(): Array { return js("[]").slice.call(this) } /** * Returns a *typed* object array containing all of the elements of this primitive array. */ public actual fun BooleanArray.toTypedArray(): Array { return js("[]").slice.call(this) } /** * Returns a *typed* object array containing all of the elements of this primitive array. */ public actual fun CharArray.toTypedArray(): Array { return Array(size) { index -> this[index] } }