Acton
Acton standard libraryTypes

big_array

big_array.tolk standard library file

Module defining BigArray<T>

Definitions

BigArray

struct BigArray<T> {
    private arr: [array<array<T>>, int]
}

BigArray<T> is a chunked array implementation for cases when regular array<T> capacity (0..255) is not enough.

Internally it stores items in bins, where each bin is array<T> with up to 255 items. New bins are created lazily on demand. Total capacity is up to 255 * 255 = 65025 items.

Example:

var list = BigArray<int>.createEmpty();
list.push(10);
list.push(20);
val first = list.first(); // 10
val last = list.last();   // 20
Source code

BigArray<T>.createEmpty

fun BigArray<T>.createEmpty(): BigArray<T>

Creates an empty BigArray.

Use this constructor to initialize a new chunked array.

Source code

BigArray<T>.createFromArray

fun BigArray<T>.createFromArray(items: array<T>): BigArray<T>

Creates BigArray and fills it with all elements from items.

Elements preserve the original order from items. All elements are copied into the first bin directly.

Source code

BigArray<T>.first

fun BigArray<T>.first(self): T

Returns the first element of a non-empty BigArray.

Fails if the array is empty.

Source code

BigArray<T>.size

fun BigArray<T>.size(self): int

Returns current number of elements in BigArray.

Source code

BigArray<T>.last

fun BigArray<T>.last(self): T

Returns the last element of a non-empty BigArray.

Fails if the array is empty.

Source code

BigArray<T>.push

fun BigArray<T>.push(mutate self, value: T): void

Appends value to the end of BigArray.

Fails if array capacity exceeds 65025 elements.

Source code

BigArray<T>.pop

fun BigArray<T>.pop(mutate self): void

Removes the last element from BigArray.

Fails if the array is empty.

Source code

BigArray<T>.set

fun BigArray<T>.set(mutate self, value: T, index: int): void

Replaces element at index with value.

Fails if index is out of bounds.

Source code

BigArray<T>.get

fun BigArray<T>.get(self, index: int): T

Returns element at index.

Fails if index is out of bounds.

Source code

BigArray<T>.each

fun BigArray<T>.each(self, f: (T -> void)): void

Calls f for every element in the BigArray.

Source code

BigArray<T>.map

fun BigArray<T>.map<U>(self, f: (T -> U)): BigArray<U>

Returns a new BigArray with f applied to every element.

Source code

BigArray<T>.filter

fun BigArray<T>.filter(self, f: (T -> bool)): BigArray<T>

Returns a new BigArray containing only elements for which f returns true.

Source code

Last updated on

On this page