Library
Module
Module type
Parameter
Class
Class type
Persistent vectors with custom branching factor.
module _ : sig ... end
val length : 'a t -> int
length v
returns the number of elements in vector v
.
val empty : unit -> 'a t
empty ()
returns a new vector of length 0.
val init : int -> (int -> 'a) -> 'a t
init n f
returns a vector of length n
holding the elements f(0)
, f(1)
, ... .
append x v
appends x
to the end of vector v
and returns the updated vector.
set i x v
replaces the i-th element of vector v
with x
and returns the updated vector. For i = length v
, set i x v
equals append x v
.
Returns None
if index i
is out of bounds.
val get : int -> 'a t -> 'a option
get i v
reads the i-th element from vector v
.
Returns None
if index i
is out of bounds.
val peek : 'a t -> 'a option
peek v
returns the last element of vector v
or None
if v
is empty.
pop v
removes the last element of vector v
and returns the removed element together with the updated vector.
Returns None
if v
is empty.
val get_exn : int -> 'a t -> 'a
get_exn
is similar to get
but raises Not_found
instead of returning None
.
set_exn
is similar to set
but raises Invalid_argument _
instead of returning None
.
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
Like List.fold_left
.
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
Similar to List.fold_right
but does not allocate additional memory.
val to_list : 'a t -> 'a list
to_list v
converts vector v
to a list.
val rev_to_list : 'a t -> 'a list
rev_to_list v
converts vector v
to a list; reverse order.
val of_list : 'a list -> 'a t
of_list v
converts list l
to a vector.
val to_array : 'a t -> 'a array
to_array v
converts vector v
to an array.
val rev_to_array : 'a t -> 'a array
rev_to_array v
converts vector v
to an array; reverse order.
val of_array : 'a array -> 'a t
of_array v
converts array l
to a vector.