Merkle
Merkle: content-addressed hash tree.
Each leaf stores a value and the SHA-256 hash of its byte representation. Each branch stores the SHA-256 hash of (left_hash ++ right_hash). The root hash summarises the entire tree; comparing root hashes detects any difference in O(1), while diff() localises changes in O(k log n) by recursing only into subtrees whose hashes differ.
build/3 constructs a balanced tree from a list of items in O(n). The caller supplies a to_bytes : a -> String function for leaf hashing.
Types
Functions
Construct a branch, hashing the concatenation of the children's root hashes.
Build a balanced Merkle tree from a non-empty list. Returns None for an empty list.
True when the tree contains a leaf whose hash equals h.
Return the leaf hashes that differ between two trees with the same structure.
Construct a leaf, hashing the value with to_bytes.
Collect all leaf hashes, left to right.
Collect all values stored at the leaves, left to right.
Return the hash stored at the root of the tree.
Number of leaves in the tree.