package containers

  1. Overview
  2. Docs
A modular, clean and powerful extension of the OCaml standard library

Install

Dune Dependency

Authors

Maintainers

Sources

v2.8.tar.gz
md5=03b80e963186e91ddac62ef645bf7fb2
sha512=c8f434808be540c16926bf03d89f394d33fc2d092f963a7b6d412481229e0a96290f1ad7c7d522415115d35426b7aa0b3fda4b991ddc321dad279d402c9a0c0b

doc/containers.data/CCPersistentArray/index.html

Module CCPersistentArraySource

Persistent Arrays

From the paper by Jean-Christophe Filliâtre, "A persistent Union-Find data structure", see the ps version

  • since 0.10
Sourcetype 'a t

The type of persistent arrays

Sourceval 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.

  • raises Invalid_argument

    if n < 0 or n > Sys.max_array_length. If the value of x is a floating-point number, then the maximum size is only Sys.max_array_length / 2.

Sourceval 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.

  • raises Invalid_argument

    if n < 0 or n > Sys.max_array_length. If the value of x is a floating-point number, then the maximum size is only Sys.max_array_length / 2.

Sourceval get : 'a t -> int -> 'a

get a i returns the element with index i from the array a.

  • raises Invalid_argument

    "index out of bounds" if n is outside the range 0 to Array.length a - 1.

Sourceval set : 'a t -> int -> 'a -> 'a t

set a i v sets the element index i from the array a to v.

  • raises Invalid_argument

    "index out of bounds" if n is outside the range 0 to Array.length a - 1.

Sourceval length : 'a t -> int

Return the length of the persistent array.

Sourceval copy : 'a t -> 'a t

copy a returns a fresh copy of a. Both copies are independent.

Sourceval map : ('a -> 'b) -> 'a t -> 'b t
Sourceval mapi : (int -> 'a -> 'b) -> 'a t -> 'b t

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)).

Sourceval 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.

Sourceval 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.

Sourceval fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
Sourceval fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b

Fold on the elements of the array.

Sourceval append : 'a t -> 'a t -> 'a t

Append the two arrays.

  • since 0.13
Sourceval flatten : 'a t t -> 'a t

Concatenates all the sub-arrays.

  • since 0.13
Sourceval flat_map : ('a -> 'b t) -> 'a t -> 'b t

Flat map (map + concatenation).

  • since 0.13
Sourceval to_array : 'a t -> 'a array

to_array t returns a mutable copy of t.

Sourceval of_array : 'a array -> 'a t

of_array a returns an immutable copy of a.

Sourceval to_list : 'a t -> 'a list

to_list t returns the list of elements in t.

Sourceval of_list : 'a list -> 'a t

of_list l returns a fresh persistent array containing the elements of l.

Sourceval of_rev_list : 'a list -> 'a t

of_rev_list l is the same as of_list (List.rev l) but more efficient.

  • since 0.13

Conversions

Sourcetype 'a sequence = ('a -> unit) -> unit
Sourcetype 'a gen = unit -> 'a option
Sourceval to_seq : 'a t -> 'a sequence
Sourceval of_seq : 'a sequence -> 'a t
Sourceval of_gen : 'a gen -> 'a t
  • since 0.13
Sourceval to_gen : 'a t -> 'a gen
  • since 0.13

IO

Sourcetype 'a printer = Format.formatter -> 'a -> unit
Sourceval pp : 'a printer -> 'a t printer
  • since 0.13
OCaml

Innovation. Community. Security.