Companion

object Companion

Types

Link copied to clipboard
fun interface ByteArrayComparator

Comparator for a fixed number of bytes.

Properties

Link copied to clipboard

Maximum length for an array (Integer.MAX_VALUE - RamUsageEstimator.NUM_BYTES_ARRAY_HEADER).

Functions

Link copied to clipboard
fun compareUnsigned(a: ByteArray, aFromIndex: Int, aToIndex: Int, b: ByteArray, bFromIndex: Int, bToIndex: Int): Int

Compare exactly the bytes in the slices [aFromIndex, aToIndex) and [bFromIndex, bToIndex) as unsigned bytes.

Link copied to clipboard
fun compareUnsigned4(a: ByteArray, aOffset: Int, b: ByteArray, bOffset: Int): Int

Compare exactly 4 unsigned bytes from the provided arrays.

Link copied to clipboard
fun compareUnsigned8(a: ByteArray, aOffset: Int, b: ByteArray, bOffset: Int): Int

Compare exactly 8 unsigned bytes from the provided arrays. This function reads a big-endian long from each array and compares them as unsigned values.

Link copied to clipboard
inline fun <T> copyArray(array: Array<T>): Array<T>

Copies an array into a new array.

Link copied to clipboard
inline fun <T> copyOfSubArray(array: Array<T>, from: Int, to: Int): Array<T>
fun copyOfSubArray(array: ByteArray, from: Int, to: Int): ByteArray
fun copyOfSubArray(array: CharArray, from: Int, to: Int): CharArray
fun copyOfSubArray(array: DoubleArray, from: Int, to: Int): DoubleArray
fun copyOfSubArray(array: FloatArray, from: Int, to: Int): FloatArray
fun copyOfSubArray(array: IntArray, from: Int, to: Int): IntArray
fun copyOfSubArray(array: LongArray, from: Int, to: Int): LongArray
fun copyOfSubArray(array: ShortArray, from: Int, to: Int): ShortArray

Copies the specified range of the given array into a new sub array.

Link copied to clipboard

Return a comparator for exactly the specified number of bytes.

Link copied to clipboard
inline fun <T> grow(array: Array<T>): Array<T>
fun grow(array: ByteArray): ByteArray
fun grow(array: CharArray): CharArray
fun grow(array: IntArray): IntArray
fun grow(array: LongArray): LongArray

Returns a larger array, generally over-allocating exponentially

@JvmName(name = "growNullable")
inline fun <T> grow(array: Array<T?>, minSize: Int): Array<T?>

inline fun <T> grow(array: Array<T>, minSize: Int): Array<T>
fun grow(array: ByteArray, minSize: Int): ByteArray
fun grow(array: CharArray, minSize: Int): CharArray
fun grow(array: DoubleArray, minSize: Int): DoubleArray
fun grow(array: FloatArray, minSize: Int): FloatArray
fun grow(array: IntArray, minSize: Int): IntArray
fun grow(array: LongArray, minSize: Int): LongArray
fun grow(array: ShortArray, minSize: Int): ShortArray

Returns an array whose size is at least minSize, generally over-allocating exponentially

Link copied to clipboard
@JvmName(name = "growExactNullable")
inline fun <T> growExact(array: Array<T?>, newLength: Int): Array<T?>

inline fun <T> growExact(array: Array<T>, newLength: Int): Array<T>
fun growExact(array: ByteArray, newLength: Int): ByteArray
fun growExact(array: CharArray, newLength: Int): CharArray
fun growExact(array: DoubleArray, newLength: Int): DoubleArray
fun growExact(array: FloatArray, newLength: Int): FloatArray
fun growExact(array: IntArray, newLength: Int): IntArray
fun growExact(array: LongArray, newLength: Int): LongArray
fun growExact(array: ShortArray, newLength: Int): ShortArray

Returns a new array whose size is exact the specified newLength without over-allocating

Link copied to clipboard
fun growInRange(array: IntArray, minLength: Int, maxLength: Int): IntArray

Returns an array whose size is at least minLength, generally over-allocating exponentially, but never allocating more than maxLength elements.

Link copied to clipboard
fun growNoCopy(array: ByteArray, minSize: Int): ByteArray
fun growNoCopy(array: IntArray, minSize: Int): IntArray
fun growNoCopy(array: LongArray, minSize: Int): LongArray

Returns an array whose size is at least minSize, generally over-allocating exponentially, and it will not copy the origin data to the new array

Link copied to clipboard
fun hashCode(array: CharArray, start: Int, end: Int): Int

Returns hash of chars in range start (inclusive) to end (inclusive)

Link copied to clipboard
fun <T : Comparable<T>> introSort(a: Array<T>)

Sorts the given array in natural order. This method uses the intro sort algorithm, but falls back to insertion sort for small arrays.

fun <T> introSort(a: Array<T>, comp: Comparator<in T>)

Sorts the given array using the Comparator. This method uses the intro sort algorithm, but falls back to insertion sort for small arrays.

fun <T : Comparable<T>> introSort(a: Array<T>, fromIndex: Int, toIndex: Int)

Sorts the given array slice in natural order. This method uses the intro sort algorithm, but falls back to insertion sort for small arrays.

fun <T> introSort(a: Array<T>, fromIndex: Int, toIndex: Int, comp: Comparator<in T>)

Sorts the given array slice using the Comparator. This method uses the intro sort algorithm, but falls back to insertion sort for small arrays.

Link copied to clipboard
fun oversize(minTargetSize: Int, bytesPerElement: Int): Int

Returns an array size >= minTargetSize, generally over-allocating exponentially to achieve amortized linear-time cost as the array grows.

Link copied to clipboard
fun parseInt(chars: CharArray, offset: Int, len: Int): Int

Parses a char array into an int.

fun parseInt(chars: CharArray, offset: Int, len: Int, radix: Int): Int

Parses the string argument as if it was an int value and returns the result. Throws NumberFormatException if the string does not represent an int quantity. The second argument specifies the radix to use when parsing the value.

Link copied to clipboard
fun <T> select(arr: Array<T>, from: Int, to: Int, k: Int, comparator: Comparator<in T>)

Reorganize arr[from:to[ so that the element at offset k is at the same position as if arr[from:to] was sorted, and all elements on its left are less than or equal to it, and all elements on its right are greater than or equal to it.

Link copied to clipboard
fun <T> swap(arr: Array<T>, i: Int, j: Int)

Swap values stored in slots i and j

Link copied to clipboard
fun <T : Comparable<T>> timSort(a: Array<T>)

Sorts the given array in natural order. This method uses the Tim sort algorithm, but falls back to binary sort for small arrays.

fun <T> timSort(a: Array<T>, comp: Comparator<in T>)

Sorts the given array using the Comparator. This method uses the Tim sort algorithm, but falls back to binary sort for small arrays.

fun <T : Comparable<T>> timSort(a: Array<T>, fromIndex: Int, toIndex: Int)

Sorts the given array slice in natural order. This method uses the Tim sort algorithm, but falls back to binary sort for small arrays.

fun <T> timSort(a: Array<T>, fromIndex: Int, toIndex: Int, comp: Comparator<in T>)

Sorts the given array slice using the Comparator. This method uses the Tim sort algorithm, but falls back to binary sort for small arrays.