crow/col/array.crow (source)

new[t] t array(...a t array) bare

Create an array with the given elements.

size[t] nat64(a t array) bare

to[t] t array(a t range) t rangeable

to[t] t array(a t?)

is-empty[t] bool(a t array) bare

true iff a.size == 0.

~[t] t array(a t, b t array)

Prepend an element to an array.
This is O(n).

~[t] t array(a t array, b t)

Append an element to an array.
This is O(n).

~~[t] t array(a t array, b t array)

Concatenates two arrays.
This is O(n).

If you need concatenate many arrays, use a mut[] to accumulate elements,
then call move-to-array.

==[t] bool(a t array, b t array) bare, t equal

<=>[t] comparison(a t array, b t array) bare, t compare

update-at[t] t array(a t array, index nat64, new-value t)

Returns a new array like a but where a[index] is new-value.
This is O(n).

index must be a valid index into a. This can't be used to add a value to the end.

insert-at[t] t array(a t array, index nat64, value t)

Inserts an element at index index, all elements there and after to the right.
Unlike for update-at, index can be a.size, though it still can't be higher.

remove-at[t] t array(a t array, index nat64)

Removes the element at index index, shifting all later elements to the left.

array-iterator[t] record

==[t] bool(a t array-iterator, b t array-iterator) t equal

<=>[t] comparison(a t array-iterator, b t array-iterator) t equal

-[t] t array-iterator(a t array-iterator, n nat64) bare

-[t] nat64(a t array-iterator, b t array-iterator) bare

+[t] t array-iterator(a t array-iterator, n nat64) bare

begin[t] t array-iterator(a t array) bare

end[t] t array-iterator(a t array) bare

prev[t] (t array-iterator, t) tuple2?(a t array-iterator) bare

next[t] (t, t array-iterator) tuple2?(a t array-iterator) bare

slice[t] t array(begin t array-iterator, end t array-iterator) bare

begin-pointer[t] t*(a t array) bare, unsafe

end-pointer[t] t*(a t array) bare, unsafe

Pointer to the end of an array.

as-array[t] t array(pointers t* range) bare, unsafe

Arr or the range from begin to end.
begin is inclusive and end is exclusive.
UB if begin > end.

pointers[t] t* range(a t array) bare, unsafe

subscript[t] t(a t array, index nat64) bare

subscript[t] t array(a t array, indices nat64 range) bare

subscript[t] t array(a t*, r nat64 range) bare, unsafe

Create an array from a range of pointers.

iterate[t] bool(a t array, f mut bool(t))

Equivalent to calling f[a[0]], f[a[1]], etc.

Calls f for each element in a.

array-builder[t] record mut

(has non-public fields)

    build[t] t array(a build-options, f mut void(t array-builder))

    size[t] nat64(a t array-builder)

    ~=[t] void(a t array-builder, value t)

    ~~=[t] void(a t array-builder, values t array)

    array[t] builtin

    Array of values.

    For a mutable version, see the mut-array module.

    This is implemented as a pointer and a length, also known as a "fat pointer".
    This means this is also the type for a slice of an array, and slicing is O(1).

    A slice does not keep the whole array alive, only the elements it can reach;
    elements not reachable by any slice will be garbage collected.