Module CCPersistentArray
Persistent Arrays
From the paper by Jean-Christophe Filliâtre, "A persistent Union-Find data structure", see the ps version
- since
- 0.10
val make : int -> 'a -> 'a tmake n xreturns a persistent array of length n, withx. 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.- raises Invalid_argument
if
n < 0orn > Sys.max_array_length. If the value of x is a floating-point number, then the maximum size is onlySys.max_array_length / 2.
val init : int -> (int -> 'a) -> 'a tinit n freturns a persistent array of length n, with elementiinitialized to the result off i.- raises Invalid_argument
if
n < 0orn > Sys.max_array_length. If the value of x is a floating-point number, then the maximum size is onlySys.max_array_length / 2.
val get : 'a t -> int -> 'aget a ireturns the element with indexifrom the arraya.- raises Invalid_argument
"index out of bounds" if
nis outside the range0toArray.length a - 1.
val set : 'a t -> int -> 'a -> 'a tset a i vsets the element indexifrom the arrayatov.- raises Invalid_argument
"index out of bounds" if
nis outside the range0toArray.length a - 1.
val length : 'a t -> intReturn the length of the persistent array.
val map : ('a -> 'b) -> 'a t -> 'b tval mapi : (int -> 'a -> 'b) -> 'a t -> 'b tApply 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 tofun f t -> init (fun i -> f (get t i)).
val iter : ('a -> unit) -> 'a t -> unititer f tapplies functionfto all elements of the persistent array, in order from element0to elementlength t - 1.
val iteri : (int -> 'a -> unit) -> 'a t -> unititer f tapplies functionfto all elements of the persistent array, in order from element0to elementlength t - 1.
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'aval fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'bFold on the elements of the array.
val to_array : 'a t -> 'a arrayto_array treturns a mutable copy oft.
val of_array : 'a array -> 'a tof_array areturns an immutable copy ofa.
val to_list : 'a t -> 'a listto_list treturns the list of elements int.
val of_list : 'a list -> 'a tof_list lreturns a fresh persistent array containing the elements ofl.
val of_rev_list : 'a list -> 'a tof_rev_list lis the same asof_list (List.rev l)but more efficient.- since
- 0.13