commonMain.dev.icerock.moko.web3.crypto.IntArrayExt.kt Maven / Gradle / Ivy
/*
* Copyright (c) 2017 ligi. Use of this source code is governed by the MIT License.
* Original: https://github.com/komputing/KHash/blob/master/keccak/src/main/kotlin/org/komputing/khash/keccak/extensions/IntArrayExtensions.kt
*/
package dev.icerock.moko.web3.crypto
/**
* Assigns the specified int value to each element of the specified
* range of the specified array of ints. The range to be filled
* extends from index fromIndex, inclusive, to index
* toIndex, exclusive. (If fromIndex==toIndex, the
* range to be filled is empty.)
*
* @param fromIndex the index of the first element (inclusive) to be
* filled with the specified value
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param value the value to be stored in all elements of the array
* @throws IllegalArgumentException if fromIndex > toIndex
* @throws ArrayIndexOutOfBoundsException if fromIndex < 0 or
* toIndex > a.length
*/
internal fun IntArray.fillWith(value: Int, fromIndex: Int = 0, toIndex: Int = this.size) {
if (fromIndex > toIndex) {
throw IllegalArgumentException(
"fromIndex($fromIndex) > toIndex($toIndex)"
)
}
if (fromIndex < 0) {
throw ArrayIndexOutOfBoundsException(fromIndex)
}
if (toIndex > this.size) {
throw ArrayIndexOutOfBoundsException(toIndex)
}
for (i in fromIndex until toIndex)
this[i] = value
}
/**
* Constructs a new [ArrayIndexOutOfBoundsException]
* class with an argument indicating the illegal index.
* @param index the illegal index.
*/
internal class ArrayIndexOutOfBoundsException(index: Int) : Throwable("Array index out of range: $index")
© 2015 - 2025 Weber Informatics LLC | Privacy Policy