keen/col/mut-array
SourceThis is a standard module
and does not need to be explicitly imported.
mut-array[t] record (has private fields)list-new[t] t mut[](a t[])reduce-size-to[t] void(a t mut[], new-size nat64)Removes all elements with index >=
new-size. This is O(1).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 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).
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.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.
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).