Indexing.Vector
The submodule Vector
allows safely manipulating indices into a vector.
type ('n, 'a) t = ('n, 'a) vector
val as_array : (_, 'a) t -> 'a array
as_array v
exposes a view of the vector v
as an ordinary array. This is a safe cast. This operation does nothing at runtime.
length
is analogous to Array.length
, but returns a cardinal instead of an ordinary integer.
get
is Array.get
, but expects an index instead of an ordinary integer. This guarantees that the index is within bounds.
set
is Array.set
, but expects an index instead of an ordinary integer. This guarantees that the index is within bounds.
set_cons t i x
is short for set t i (x :: get t i)
.
make
is analogous to Array.make
. Invoking make n x
fixes the cardinal n
.
make' n f
is roughly analogous to make n (f())
, but removes the need to exhibit a value of type 'a
when n
is zero. The function call f()
takes place only if n
is greater than zero. It takes place at most once. Invoking make' n f
fixes the cardinal n
.
init
is analogous to Array.init
. Invoking init n f
fixes the cardinal n
.
val fold_right : ('b -> 'a -> 'a) -> (_, 'b) t -> 'a -> 'a
fold_right
is Array.fold_right
.
fold_left2 f accu v1 v2
folds the function f
with initial accumulator accu
simultaneously over the vectors v1
and v2
. The elements of the vectors are processed left to right.
fold_right2 f v1 v2 accu
folds the function f
with initial accumulator accu
simultaneously over the vectors v1
and v2
. The elements of the vectors are processed right to left.
Suppose v
is a vector that maps indices in the range [0,m)
to indices in the range [0,n)
, and suppose that v
represents an injective function. Then, invert n v
returns a vector that represents the inverse function, a partial function of [0,n)
into [0,m)
.
of_array n a
checks that the cardinal n
is equal to the length of the array a
and converts the array a
to a vector. If the cardinal n
is not yet fixed, then, as a side effect of this call, it becomes fixed.
module type V = sig ... end
The module type V
is a module-level analogue of the type vector
.