package tezos-context
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=296bb5674bc6050afe6330326fbdd0dfc2255d414bfd6b79cc7666ac6b39316d
sha512=c061cd300a9410300851158d77bf8e56ca3c568b0b1161b38305e5b2efdcd9c746d391f832fdb2826f9a1d6babce10a9b764a4b04f5df42699f7314b9863123a
doc/tezos-context.helpers/Tezos_context_helpers/Context/Make_tree/argument-1-DB/Tree/index.html
Module DB.Tree
Managing store's trees.
Tree provides immutable, in-memory partial mirror of the store, with lazy reads and delayed writes.
Trees are like staging area in Git: they are immutable temporary non-persistent areas (they disappear if the host crash), held in memory for efficiency, where reads are done lazily and writes are done only when needed on commit: if you modify a key twice, only the last change will be written to the store when you commit.
Constructors
val empty : treeempty is the empty tree. The empty tree does not have associated backend configuration values, as they can perform in-memory operation, independently of any given backend.
of_contents c is the subtree built from the contents c.
val kinded_hash_t :
[ `Contents of hash * metadata | `Node of hash ] Irmin.Type.tpruned h is a purely in-memory tree with the hash h. Such trees can be used as children of other in-memory tree nodes, for instance in order to compute the hash of the parent, but they cannot be dereferenced.
Any operation that would require loading the contents of a pruned node (e.g. calling find on one of its children) will instead raise a Pruned_hash exception. Attempting to export a tree containing pruned sub-trees to a repository will fail similarly.
kind t k is the type of s in t. It could either be a tree node or some file contents. It is None if k is not present in t.
val is_empty : tree -> boolDiffs
diff x y is the difference of contents between x and y.
Manipulating Contents
Operations on lazy nodes can fail if the underlying store does not contain the expected hash.
The exception raised by functions that can force lazy tree nodes but do not return an explicit or_error.
The exception raised by functions that attempt to load pruned tree nodes.
module Contents : sig ... endOperations on lazy tree contents.
find_all t k is Some (b, m) if k is associated to the contents b and metadata m in t and None if k is not present in t.
find is similar to find_all but it discards metadata.
Same as find_all but raise Invalid_arg if k is not present in t.
list t key is the list of files and sub-nodes stored under k in t. The result order is not specified but is stable.
offset and length are used for pagination.
cache defaults to true, see caching for an explanation of the parameter.
add t k c is the tree where the key k is bound to the contents c but is similar to t for other bindings.
val update :
tree ->
key ->
?metadata:metadata ->
(contents option -> contents option) ->
tree Lwt.tupdate t k f is the tree t' that is the same as t for all keys except k, and whose binding for k is determined by f (find t k).
If k refers to an internal node of t, f is called with None to determine the value with which to replace it.
remove t k is the tree where k bindings has been removed but is similar to t for other bindings.
Manipulating Subtrees
find_tree t k is Some v if k is associated to v in t. It is None if k is not present in t.
get_tree t k is v if k is associated to v in t. Raise Invalid_arg if k is not present in t.
add_tree t k v is the tree where the key k is bound to the non-empty tree v but is similar to t for other bindings.
If v is empty, this is equivalent to remove t k.
update_tree t k f is the tree t' that is the same as t for all subtrees except under k, and whose subtree at k is determined by f (find_tree t k).
f returning either None or Some empty causes the subtree at k to be unbound (i.e. it is equivalent to remove t k).
val merge : tree Irmin.Merge.tmerge is the 3-way merge function for trees.
Folds
val destruct : tree -> [ `Node of node | `Contents of Contents.t * metadata ]General-purpose destructor for trees.
val empty_marks : unit -> marksempty_marks () is an empty collection of marks.
The type for fold's force parameter. `True forces the fold to read the objects of the lazy nodes and contents. `False f is applying f on every lazy node and content value instead.
The type for fold's uniq parameters. `False folds over all the nodes. `True does not recurse on nodes already seen. `Marks m uses the collection of marks m to store the cache of keys: the fold will modify m. This can be used for incremental folds.
The type for fold depths.
Eq dfolds over nodes and contents of depth exactlyd.Lt dfolds over nodes and contents of depth strictly less thand.Gt dfolds over nodes and contents of depth strictly more thand.
Le d is Eq d and Lt d. Ge d is Eq d and Gt d.
val depth_t : depth Irmin.Type.tval fold :
?order:[ `Sorted | `Undefined | `Random of Random.State.t ] ->
?force:'a force ->
?cache:bool ->
?uniq:uniq ->
?pre:'a node_fn ->
?post:'a node_fn ->
?depth:depth ->
?contents:(key -> contents -> 'a -> 'a Lwt.t) ->
?node:(key -> node -> 'a -> 'a Lwt.t) ->
?tree:(key -> tree -> 'a -> 'a Lwt.t) ->
tree ->
'a ->
'a Lwt.tfold f t acc folds f over t's leafs.
For every node n, ui n is a leaf node, call f path n. Otherwise:
- Call
pre path n. By defaultpreis the identity; - Recursively call
foldon each children. - Call
post path n; By defaultpostis the identity.
See force for details about the force parameters. By default it is `True.
See uniq for details about the uniq parameters. By default it is `False.
The fold depth is controlled by the depth parameter.
cache defaults to false, see caching for an explanation of the parameter.
If order is `Sorted (the default), the elements are traversed in lexicographic order of their keys. If `Random state, they are traversed in a random order. For large nodes, these two modes are memory-consuming, use `Undefined for a more memory efficient fold.
Stats
type stats = {nodes : int;(*Number of node.
*)leafs : int;(*Number of leafs.
*)skips : int;(*Number of lazy nodes.
*)depth : int;(*Maximal depth.
*)width : int;(*Maximal width.
*)
}The type for tree stats.
val stats_t : stats Irmin.Type.tstats ~force t are t's statistics. If force is true, this will force the reading of lazy nodes. By default it is false.
Concrete Trees
The type for concrete trees.
val concrete_t : concrete Irmin.Type.tThe value-type for concrete.
to_concrete t is the concrete tree equivalent of the subtree t.
Proofs
module Proof : sig ... endCaches
val clear : ?depth:int -> tree -> unitclear ?depth t clears all caches in the tree t for subtrees with a depth higher than depth. If depth is not set, all of the subtrees are cleared.
A call to clear doesn't discard the subtrees of t, only their cache are discarded. Even the lazily loaded and unmodified subtrees remain.
Performance counters
val counters : unit -> countersval dump_counters : unit Fmt.tval inspect :
tree ->
[ `Contents | `Node of [ `Map | `Hash | `Value | `Pruned ] ]Import/Export
val of_hash : Repo.t -> kinded_hash -> tree option Lwt.tof_hash r h is the the tree object in r having h as hash, or None is no such tree object exists.
val shallow : Repo.t -> kinded_hash -> treeshallow r h is the shallow tree object with the hash h. No check is performed to verify if h actually exists in r.