crow/col/mut-slice.crow (source)
==[t] bool(a t mut-slice, b t mut-slice) bare
True if they are identical.
new[t] t mut-slice(...a t array) bare
Creates a new mut-slice with the given elements.
subscript[t] t mut-slice(a t mut*, indices nat64 range) bare, unsafe
Get a mut-slice from a pointer and range of indices.
to[t] t mut-slice(a t array)
Copies the array elements to a new mut-slice.
This is O(n).
to[t] t array(a t mut-slice)
Copies the elements to an immutable array.
This is O(n).
There is no move-to for mut-slice since there might be slices that still refer to its elements.
as-mut-slice[t] t mut-slice(a t mut* range) bare, unsafe
Creates a mut-slice from a range of pointers.
pointers[t] t mut* range(a t mut-slice) bare, unsafe
size[t] nat64(a t mut-slice) bare
Number of elements.
is-empty[t] bool(a t mut-slice) bare
true iff a.size == 0.
begin-pointer[t] t mut*(a t mut-slice) bare, unsafe
Pointer to the beginning of the mut-slice.
end-pointer[t] t mut*(a t mut-slice) bare, unsafe
Pointer to the end of the mut-slice.
This is one past the last valid pointer.
copy[t] t mut-slice(a t mut-slice)
Copies the elements to a new mut-slice.
This is O(n).
subscript[t] t(a t mut-slice, index nat64) bare
set-subscript[t] void(a t mut-slice, index nat64, value t) bare
subscript[t] t mut-slice(a t mut-slice, indices nat64 range) bare
set-subscript[t] void(dest t mut-slice, range nat64 range, source t array) bare
Copies elements from source to dest.
Throws if dest and source are not the same size.
set-subscript[t] void(dest t mut-slice, range nat64 range, source t mut-slice) bare
set-subscript[t] void(dest t mut-slice, range range-relative-to-end, source t array) bare
set-subscript[t] void(dest t mut-slice, range range-relative-to-end, source t mut-slice) bare
swap[t] void(a t mut-slice, i nat64, j nat64) bare
gc-safe-mut-slice[t] t mut-slice(size nat64) unsafe
Allocates a mut-slice full of GC-safe values. See gc-safe-value.
If you just want to create a mut-slice, use a for loop instead.
Keep exceptions in mind: Don't store a reference to the result until it's initialized,
since initialization code might throw an exception.
This is used by collections like mut[] that need some excess capacity that will be GC-safe.
clear-memory[t] void(a t mut-slice) bare, unsafe
Sets every element to gc-safe-value.
See gc-safe-mut-slice for why this is unsafe.
in[t] bool(value t, a t mut-slice) bare, t equal
equalcast-immutable[t] t array(a t mut-slice) bare, unsafe
Unsafe cast a mut-slice to an array.
It must never be written to again.
temp-as-array[t] t array(a t mut-slice) bare, unsafe
Unsafe cast to immutable array.
This is O(1).
Unsafe because an array is expected to be fully immutable (meaning: no mutable references exist),
so this value must only be used temporarily.
cast-mut-slice[out, in] out mut-slice(a in mut-slice) bare, unsafe
Casts elements to a different type.
If the element type is different, adjusts the size so that the number of bytes is the same.
iterate[t] bool(a t mut-slice, f mut bool(t))
Calls 'f' on each element in the mut-slice.
mut-slice-iterator[t] record mut
(has non-public fields)
begin[t] t mut-slice-iterator(a t mut-slice) bare
end[t] t mut-slice-iterator(a t mut-slice) bare
+[t] t mut-slice-iterator(a t mut-slice-iterator, b nat64) bare
-[t] t mut-slice-iterator(a t mut-slice-iterator, b nat64) bare
-[t] nat64(a t mut-slice-iterator, b t mut-slice-iterator) bare
prev[t] (t mut-slice-iterator, t) tuple2?(a t mut-slice-iterator) bare
next[t] (t, t mut-slice-iterator) tuple2?(a t mut-slice-iterator) bare
set-prev[t] void(a t mut-slice-iterator, value t) bare
set-next[t] void(a t mut-slice-iterator, value t) bare
slice[t] t mut-slice(begin t mut-slice-iterator, end t mut-slice-iterator) bare
JS can't slice a 'mut-slice', so this is only available in native code.
mut-slice-builder[t] record mut
(has non-public fields)
build[t] t mut-slice(a build-options, f mut void(t mut-slice-builder))
~=[t] void(a t mut-slice-builder, value t)
~~=[t] void(a t mut-slice-builder, values t array)
size[t] nat64(a t mut-slice-builder)
mut-slice[t] builtin
This is a low-level type mostly useful for implementing other collections.
For normal code, a mut[] is preferable.
A mut-slice is like a mut[],
but while a mut[] has capacity for pushing elements, mut-slice is fixed-size.
This has a small performance benefit for native code, since (like an immutable array)
a mut-slice is just a pointer and size which can be stored by value.
You can't change what range of addresses a mut-slice points to,
though you can write to its elements.
Like an immutable array, and unlike a mut[], it's cheap to take a slice of a mut-slice.
Taking a slice aliases the elements, so writing to the slice writes to the original.