package octez-libs

  1. Overview
  2. Docs
type key = Z.t
type 'a producer = key -> 'a Lwt.t
module Map : Lazy_map.S with type key = key
type 'a t
val pp : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit

pp pp_value gives you a pretty-printer. This function is a witness of internal mutation.

val to_string : ('a -> string) -> 'a t -> string

to_string show vector generates a string representation of vector by using show for its values. Like pp this function is witness of internal mutation.

val string_of_key : key -> string

string_of_key key turns the given key into a string.

val num_elements : 'a t -> key

num_elements vector returns the maximum number of elements in the lazy vector.

val create : ?first_key:key -> ?values:'a Map.Map.t -> ?produce_value:'a producer -> ?origin:Tezos_tree_encoding.wrapped_tree -> key -> 'a t

create ?first_key ?values ?produce_value ?origin num_elements produces a lazy vector with num_elements entries where each is created using produce_value. values may be provided to supply an initial set of entries. first_key specifies the first index of the vector if given and defaults to zero.

Note: The produce_value and origin arguments are expected to be used by the 'tree-encoding' library. If you want to pre-fill your vector, creates an empty vector and use grow or set.

val origin : 'a t -> Tezos_tree_encoding.wrapped_tree option

origin vec returns the tree of origin of the vector, if it exists.

Note: The sole consumer of this function is expected to be the tree-encoding library.

val empty : unit -> 'a t

empty () creates a vector of size zero. This is used in conjunction with cons to model list-like structure.

val singleton : 'a -> 'a t

singleton v creates a vector of size one containing only v.

val of_list : 'a list -> 'a t

of_list values creates a vector where each association is the index in the list to its value. The first item's key is zero, the second is succ zero and so on.

Note: This function may be dangerous to use in a tick, if the size of of_list is unbounded.

val get : key -> 'a t -> 'a Lwt.t

get key vector retrieves the element at key.

  • raises Exn.Bounds

    when trying to access an invalid key

val set : key -> 'a -> 'a t -> 'a t

set key value vector sets the element at key to value.

  • raises Exn.Bounds

    when trying to set an invalid key

val cons : 'a -> 'a t -> 'a t

cons value vector prepends a value to the front and grows the vector by one. That value can then be accessed using the zero key.

val split : 'a t -> key -> 'a t * 'a t

split vec at splits vec into two sub vectors at element at. The first vector has at elements, the second length vec - at elements.

  • raises Bounds

    when at > num_elements vec

val grow : ?default:(unit -> 'a) -> key -> 'a t -> 'a t

grow delta ?default vector creates a new lazy vector that has delta more items than vector. This also retains all values that have previously been created. New values will be created with default if provided.

Note: This function may be dangerous to use in a tick, if delta is unbounded, or if the result of default is large.

val drop : 'a t -> 'a t

drop vector removes the head from vector without returning it. It doesn't read the value before removing it.

  • raises Bounds

    when applied on an empty vector.

val pop : 'a t -> ('a * 'a t) Lwt.t

pop vector removes the head from vector, and returns it.

  • raises Bounds

    when applied on an empty vector.

val prepend_list : 'a list -> 'a t -> 'a t

prepend_list l vec adds the elements of l at the front of vec.

Note: This function may be dangerous to use in a tick, if List.length l is significant.

val append : 'a -> 'a t -> 'a t * key

append elt vector creates a new lazy vector that has one more item than vector whose value is elt. This is a shortcut for vector |> grow Key.(succ zero) |> set (num_elements vector) elt. Also returns the key of the added element.

val concat : 'a t -> 'a t -> 'a t Lwt.t

concat lhs rhs concatenates two lazy vectors.

Note: This function maybe dangerous to use in a tick because every entries of both lhs and rhs will be loaded in memory.

val unsafe_concat : 'a t -> 'a t -> 'a t

unsafe_concat concatenates two lazy vectors, assuming every entries of both vectors are already loaded in memory.

val to_list : 'a t -> 'a list Lwt.t

to_list vector extracts all values of the given vector and collects them in a list.

Note: This function may be dangerous to use in a tick because all entries of the vector are loaded in memory.

val loaded_bindings : 'a t -> (key * 'a option) list

loaded_bindings vector returns the (key * 'a) list representation of the vector vector containing only the loaded values, in order of increasing keys. This function is a witness of internal mutations.

val first_key : 'a t -> key

first_key v returns the first key of the given vector v.

encoding len_encoding elem_encoding returns Tezos_tree_encoding for the vector

OCaml

Innovation. Community. Security.