plebeia

Merkle Patricia tree implementation
Library plebeia
Module Plebeia . Roots
module RootHash : sig ... end

Hash stored in the roots can be different from Plebeia's root Merkle hashes. Its length is 32bytes.

module Entry : sig ... end
type entry = Entry.t = {
meta : string;
prev : Plebeia__Index.t option;
parent : Plebeia__Index.t option;
index : Plebeia__Index.t;
hash : RootHash.t;
}
type t

Storage type

val create : storage_context:Plebeia__Storage.storage -> storage_roots:Plebeia__Storage.storage -> t

Load root hashes of the context and return t

val read_additional_commits : t -> ( int, unit ) Result.t

Reload additional commits from the updated context.

Readers must call Storage.sync prior to it in order to load new roots added by the Writer.

val sync : t -> unit

For reader, to update the root table informat which may be updated by the writer

val add : t -> ?parent:Plebeia__Index.t -> RootHash.t -> Plebeia__Index.t -> meta:string -> unit

Add a new root hash, with its index, parent, meta commit log.

It immediately saves the root to the context.

If the root hash already exists in the table, it is overridden with the new one by add.

val mem : t -> RootHash.t -> bool

Existence check. O(1) using hash table

val find : t -> RootHash.t -> Entry.t option

Find a root of the given hash. O(1) using hash table

val find_by_index : t -> Plebeia__Index.t -> Entry.t option

Find by index. O(1) using hash table

val genesis : t -> Entry.t list

Returns the hashes which have no parents. O(n)

val children : t -> Entry.t -> Entry.t list

Returns the childlren of the entry. O(1) using hash table

val fold : ( Entry.t -> 'acc -> 'acc ) -> t -> 'acc -> 'acc

folding. The entries are applied in the order of registration, from the eldest to the newest.

val fold_breadth_first : ( Entry.t -> 'acc -> 'acc ) -> t -> 'acc -> 'acc

Breadth first iteration of roots from genesis to the latest. Parents are always called before their children.

val iter : ( Entry.t -> unit ) -> t -> unit

Iteration

val length : t -> int

The number of entries in the table

val to_seq : t -> Entry.t Seq.t

The entries in the table. The ordering is not specified.

val get_latest : t -> Entry.t option

Get the latest addition