merkel v1.0.5 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 (use your discretion if you want the tree to be more compact)

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

Convert tree to erlang term format

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

Store tree to file path p, in erlang term format

Returns a list of the tree's key-value pairs in {k,v} tuple form. Pairs are extracted from the tree bottom left to bottom right.

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

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

Given a list of atom key and binary value pairs, the atom options are :etf and :path to support creation from either a merkel etf binary or a file containing a merkel etf binary

Link to this function

create(list)

create(none() | list()) :: 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

dump(t)

dump(t()) :: binary()

Convert tree to erlang term format

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

store(t, p)

store(t(), binary()) :: :ok | no_return()

Store tree to file path p, in erlang term format

Link to this function

to_list(binary_hash_tree)

to_list(t()) :: list()

Returns a list of the tree's key-value pairs in {k,v} tuple form. Pairs are extracted from the tree bottom left to bottom right.

Link to this function

tree_hash(arg1)

tree_hash(nil | t()) :: nil | binary()
Link to this function

values(binary_hash_tree)

values(t()) :: list()

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