package plebeia

  1. Overview
  2. Docs

Module Plebeia.RootsSource

1 Root hash table

All the data should be in memory.

The root hashes are stored in the context. They are chained and the last root hash entry is recorded in the header of the context.

Note that the chain of root hashes in the context do not correspond with the parent-children relationship of root hashes.

Sourcemodule RootHash : sig ... end

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

Sourcemodule Entry : sig ... end
Sourcetype entry = Entry.t = {
  1. meta : string;
  2. prev : Plebeia__.Index.t option;
  3. parent : Plebeia__.Index.t option;
  4. index : Plebeia__.Index.t;
  5. hash : RootHash.t;
}
Sourcetype t

Storage type

Sourceval create : storage_context:Plebeia__.Storage.storage -> storage_roots:Plebeia__.Storage.storage -> t

Load root hashes of the context and return t

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

Sourceval sync : t -> unit

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

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

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

Existence check. O(1) using hash table

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

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

Sourceval find_by_index : t -> Plebeia__.Index.t -> Entry.t option

Find by index. O(1) using hash table

Sourceval genesis : t -> Entry.t list

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

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

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

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

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

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

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

Iteration

Sourceval length : t -> int

The number of entries in the table

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

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

Sourceval get_latest : t -> Entry.t option

Get the latest addition

OCaml

Innovation. Community. Security.