package octez-libs
Parameters
Signature
type key = Key.t
module Map : Lazy_map.S with type key = key
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.
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.
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.
split vec at
splits vec
into two sub vectors at element at
. The first vector has at
elements, the second length vec
- at
elements.
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.
drop vector
removes the head from vector
without returning it. It doesn't read the value before removing it.
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.
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.
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.
unsafe_concat
concatenates two lazy vectors, assuming every entries of both vectors are already loaded in memory.
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.
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 encoding :
key Tezos_tree_encoding.t ->
'a Tezos_tree_encoding.t ->
'a t Tezos_tree_encoding.t
encoding len_encoding elem_encoding
returns Tezos_tree_encoding
for the vector