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(); // 20BigArray<T>.createEmpty
fun BigArray<T>.createEmpty(): BigArray<T>Creates an empty BigArray.
Use this constructor to initialize a new chunked array.
Source codeBigArray<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 codeBigArray<T>.first
fun BigArray<T>.first(self): TReturns the first element of a non-empty BigArray.
Fails if the array is empty.
Source codeBigArray<T>.size
fun BigArray<T>.size(self): intReturns current number of elements in BigArray.
Source codeBigArray<T>.last
fun BigArray<T>.last(self): TReturns the last element of a non-empty BigArray.
Fails if the array is empty.
Source codeBigArray<T>.push
fun BigArray<T>.push(mutate self, value: T): voidAppends value to the end of BigArray.
Fails if array capacity exceeds 65025 elements.
Source codeBigArray<T>.pop
fun BigArray<T>.pop(mutate self): voidRemoves the last element from BigArray.
Fails if the array is empty.
Source codeBigArray<T>.set
fun BigArray<T>.set(mutate self, value: T, index: int): voidReplaces element at index with value.
Fails if index is out of bounds.
Source codeBigArray<T>.get
fun BigArray<T>.get(self, index: int): TReturns element at index.
Fails if index is out of bounds.
Source codeBigArray<T>.each
fun BigArray<T>.each(self, f: (T -> void)): voidCalls f for every element in the BigArray.
Source codeBigArray<T>.map
fun BigArray<T>.map<U>(self, f: (T -> U)): BigArray<U>Returns a new BigArray with f applied to every element.
Source codeBigArray<T>.filter
fun BigArray<T>.filter(self, f: (T -> bool)): BigArray<T>Returns a new BigArray containing only elements for which f returns true.
Last updated on