package plebeia

  1. Overview
  2. Docs

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.

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 = {
  1. meta : string;
  2. prev : Plebeia__.Index.t option;
  3. parent : Plebeia__.Index.t option;
  4. index : Plebeia__.Index.t;
  5. hash : RootHash.t;
type t

Storage type

val create : -> -> 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


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


Innovation. Community. Security.