keen/col/mut-array

Source
This is a standard module and does not need to be explicitly imported.
mut-array[t] record (has private fields)

Mutable array type that can change in size.

Appending (or removing) elements to the end is amortized O(1), but appending (or removing) from the beginning is always O(N).

is-empty[t] bool(a t mut[])
true if a.size == 0.
size[t] nat64(a t mut[])
subscript[t] t(a t mut[], index nat64)
subscript[t] t(a t mut[], index index-relative-to-end)
set-subscript[t] void(a t mut[], index nat64, value t)
set-subscript[t] void(a t mut[], index index-relative-to-end, value t)
list-new[t] t mut[](a t[])
to[t] t mut[](a t[])
Copy elements to a new mut-array.
clear[t] void(a t mut[])
Removes all elements. This is O(1).
reduce-size-to[t] void(a t mut[], new-size nat64)
Removes all elements with index >= new-size. This is O(1).
copy[t] t mut[](a t mut[])
Copies elements to a new mut-array.
to[t] t[](a t mut[])
Copies elements to a new array. The result is immutable and won't be affected by future writes to a.
move-to[t] t[](a t mut[])
This is like to but sets the input to empty. This allows safely returning an immutable result but avoids needing to copy elements. This os O(1) normally. In JS it is likely O(n).
move-to[t] t buffer(a t mut[])
move-to[t] t mut[](a t mut[])
swap[t] void(a t mut[], b t mut[])
Swap the contents of two arrays. This is O(1) normally. In JS it is likely O(n).
swap[t] void(a t mut[], i nat64, j nat64)
peek[t] t option(a t mut[])
pop[t] t option(a t mut[])
Removes the last element and returns it. This is O(1). Returns an empty option if is-empty a.
pop-left[t] t option(a t mut[])
Removes the first element and returns it. Returns an empty option if is-empty a. This is O(n).
pop-n[t] t[](a t mut[], n nat64)
Removes the last n elements and returns them as an array. The result is guaranteed to be of size n. Throws index-too-big if there are not at least n elements.
pop-n-left[t] t[](a t mut[], n nat64)
Removes the first n elements and returns them as an array. The result is guaranteed to be of size n. Throws index-too-big if there are not at least n elements.
prepend=[t] void(a t mut[], value t)
Push a value onto the beginning of the array. This is O(n).
~=[t] void(a t mut[], value t)
Push a value onto the end of the array.
~~=[t] void(a t mut[], values t array-view)
Push multiple values onto the end of the array.
~~=[t] void(a t mut[], values t mut[])
~~=[t] void(a t mut[], values t buffer-view)
insert-at[t] void(a t mut[], index nat64, value t)
The new contents of a will be a[0 .. index] ~~ (value,) ~~ a[index .. end]. So, a[index] will be value. This is O(a.size - index) due to having to move a[index .. end] to the right by 1.
remove-at[t] t(a t mut[], index nat64)
The new contents of a will be a[0 .. index] ~~ a[index + 1 .. end]. Returns the old a[index] which will have been removed. This is O(a.size - index) due to having to shift a[index + 1 .. end] to the left by 1.
map=[t] void(a t mut[], f t mut(t))
Replaces every element x with f[x]. This locks a for both reading and writing. If f throws an exception, a will reflect all updated values so far, with unprocessed values unchanged.
filter=[t] void(a t mut[], f bool mut(t))
Removes every element x where !f[x]. If f throws an exception, a will contain only processed elements.
some[t] bool(a t mut[], f bool mut(t))
some-reverse[t] bool(a t mut[], f bool mut(t))