merkel v0.5.0 Merkel.BinaryHashTree

Implements a merkle binary hash tree that is balanced using AVL rotations

Supports create, lookup, keys, insert, delete operations

Given an initial list of k-v pairs constructs an initial balanced tree without any initial rotations or initial rehashings

Keys are binary, e.g. a utf8 encoded sequence of bytes (string) or just bytes Values are any type but for compactness binary or numbers are preferred

Keys and values are only stored in the leaves Inner nodes use the search_key value to determine order

Hashes of the keys are stored in the node key_hash field Inner nodes store the concatenated hashes of their children in key_hash as well

Link to this section Summary

Functions

Create balanced tree given a list of {k,v} pairs or create empty tree

Delete the specified key, ensuring it resides in the tree. Updates binary tree search keys

Provides dump of tree info to be used in Inspect protocol implementation

Adds key value pair and then ensures tree is balanced

Returns list of keys from bottom left of tree to bottom right

Returns key value pair if key lookup is successful

Link to this section Types

Link to this type key()
key() :: binary()
Link to this type pair()
pair() :: {key(), value()}
Link to this type t()
t() :: %Merkel.BinaryHashTree{root: term(), size: term()}
Link to this type value()
value() :: any()

Link to this section Functions

Create balanced tree given a list of {k,v} pairs or create empty tree

Link to this function create(list)
create(none() | [pair()]) :: t() | no_return()
Link to this function delete(t, key)
delete(t(), key()) :: {:ok, t()} | {:error, String.t()}

Delete the specified key, ensuring it resides in the tree. Updates binary tree search keys

Link to this function info(tree)
info(t()) :: nil | tuple()

Provides dump of tree info to be used in Inspect protocol implementation

Link to this function insert(tree, data)
insert(t(), pair()) :: t()

Adds key value pair and then ensures tree is balanced.

Link to this function keys(binary_hash_tree)
keys(t()) :: list()

Returns list of keys from bottom left of tree to bottom right

Link to this function lookup(binary_hash_tree, key)
lookup(t(), key()) :: {:ok, any()} | {:error, String.t()}

Returns key value pair if key lookup is successful

Link to this function size(arg1)
size(nil | t()) :: nil | non_neg_integer()
Link to this function tree_hash(arg1)
tree_hash(nil | t()) :: nil | String.t()