copyInto: copying elements between two arrays

#KT-25874 Fixed
This commit is contained in:
Ilya Gorbunov
2018-08-21 08:56:17 +03:00
parent 58e6f910bc
commit ea37a65178
8 changed files with 900 additions and 0 deletions
@@ -5572,6 +5572,177 @@ public expect fun BooleanArray.contentToString(): String
@SinceKotlin("1.1")
public expect fun CharArray.contentToString(): String
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
public expect fun <T> Array<out T>.copyInto(destination: Array<T>, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): Array<T>
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
public expect fun ByteArray.copyInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): ByteArray
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
public expect fun ShortArray.copyInto(destination: ShortArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): ShortArray
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
public expect fun IntArray.copyInto(destination: IntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): IntArray
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
public expect fun LongArray.copyInto(destination: LongArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): LongArray
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
public expect fun FloatArray.copyInto(destination: FloatArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): FloatArray
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
public expect fun DoubleArray.copyInto(destination: DoubleArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): DoubleArray
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
public expect fun BooleanArray.copyInto(destination: BooleanArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): BooleanArray
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
public expect fun CharArray.copyInto(destination: CharArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): CharArray
/**
* Returns new array which is a copy of the original array.
*
@@ -225,6 +225,98 @@ public fun UShortArray.contentToString(): String {
return joinToString(", ", "[", "]")
}
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UIntArray.copyInto(destination: UIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): UIntArray {
return UIntArray(storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex))
}
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun ULongArray.copyInto(destination: ULongArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): ULongArray {
return ULongArray(storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex))
}
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UByteArray.copyInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): UByteArray {
return UByteArray(storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex))
}
/**
* 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 [destinationIndex],
* or when that index is out of the [destination] array indices range.
*
* @return the [destination] array.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun UShortArray.copyInto(destination: UShortArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = -1): UShortArray {
return UShortArray(storage.copyInto(destination.storage, destinationOffset, startIndex, endIndex))
}
/**
* Returns new array which is a copy of the original array.
*