package pvec

  1. Overview
  2. Docs

Module Pvec.MakeSource

Persistent vectors with custom branching factor.

Parameters

module _ : sig ... end

Signature

Basics

Sourcetype 'a t

Persistent vectors with elements of type 'a.

Sourceval length : 'a t -> int

length v returns the number of elements in vector v.

Sourceval empty : unit -> 'a t

empty () returns a new vector of length 0.

Sourceval init : int -> (int -> 'a) -> 'a t

init n f returns a vector of length n holding the elements f(0), f(1), ... .

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

append x v appends x to the end of vector v and returns the updated vector.

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

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.

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

Sourceval peek : 'a t -> 'a option

peek v returns the last element of vector v or None if v is empty.

Sourceval pop : 'a t -> ('a * 'a t) option

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.

Unsafe of get and set

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

get_exn is similar to get but raises Not_found instead of returning None.

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

set_exn is similar to set but raises Invalid_argument _ instead of returning None.

Iterators

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

Like List.map.

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

Like List.mapi.

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

Similar to List.fold_right but does not allocate additional memory.

Sourceval iter : ('a -> unit) -> 'a t -> unit

Like List.iter.

Sourceval rev_iter : ('a -> unit) -> 'a t -> unit

Like iter but in reverse order.

Converters

Sourceval to_seq : 'a t -> 'a Seq.t

to_seq v iterates over vector v front-to-back.

Sourceval rev_to_seq : 'a t -> 'a Seq.t

rev_to_seq v iterates over vector v back-to-front.

Sourceval of_seq : 'a Seq.t -> 'a t

of_seq s stores the elements of sequence s in a vector.

Sourceval to_list : 'a t -> 'a list

to_list v converts vector v to a list.

Sourceval rev_to_list : 'a t -> 'a list

rev_to_list v converts vector v to a list; reverse order.

Sourceval of_list : 'a list -> 'a t

of_list v converts list l to a vector.

Sourceval to_array : 'a t -> 'a array

to_array v converts vector v to an array.

Sourceval rev_to_array : 'a t -> 'a array

rev_to_array v converts vector v to an array; reverse order.

Sourceval of_array : 'a array -> 'a t

of_array v converts array l to a vector.

OCaml

Innovation. Community. Security.