CCPersistentArray
From the paper by Jean-Christophe Filliâtre, "A persistent Union-Find data structure", see the ps version
val make : int -> 'a -> 'a t
make n x
returns a persistent array of length n, with x
. All the elements of this new array are initially physically equal to x (in the sense of the == predicate). Consequently, if x is mutable, it is shared among all elements of the array, and modifying x through one of the array entries will modify all other entries at the same time.
val init : int -> (int -> 'a) -> 'a t
init n f
returns a persistent array of length n, with element i
initialized to the result of f i
.
val get : 'a t -> int -> 'a
get a i
returns the element with index i
from the array a
.
val length : 'a t -> int
Return the length of the persistent array.
Apply the given function to all elements of the array, and return a persistent array initialized by the results of f. In the case of mapi
, the function is also given the index of the element. It is equivalent to fun f t -> init (fun i -> f (get t i))
.
val iter : ('a -> unit) -> 'a t -> unit
iter f t
applies function f
to all elements of the persistent array, in order from element 0
to element length t - 1
.
val iteri : (int -> 'a -> unit) -> 'a t -> unit
iter f t
applies function f
to all elements of the persistent array, in order from element 0
to element length t - 1
.
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
Fold on the elements of the array.
val to_array : 'a t -> 'a array
to_array t
returns a mutable copy of t
.
val of_array : 'a array -> 'a t
of_array a
returns an immutable copy of a
.
val to_list : 'a t -> 'a list
to_list t
returns the list of elements in t
.
val of_list : 'a list -> 'a t
of_list l
returns a fresh persistent array containing the elements of l
.
val of_rev_list : 'a list -> 'a t
of_rev_list l
is the same as of_list (List.rev l)
but more efficient.