merkle_patricia_tree v0.2.5 MerklePatriciaTree.ListHelper
Helpers for navigating lists, specifically for finding shared prefixes and postfixes.
Link to this section Summary
Functions
Returns the post of list A if starts with list B, otherwise nil
Returns the overlap of two lists in terms of a shared prefix, then the relative postfixes
Link to this section Functions
Returns the post of list A if starts with list B, otherwise nil
Examples
iex> MerklePatriciaTree.ListHelper.get_postfix([1,2,3], [1,2]) [3]
iex> MerklePatriciaTree.ListHelper.get_postfix([1,2,3,4], [1,2]) [3,4]
iex> MerklePatriciaTree.ListHelper.get_postfix([1,2,3,4], [1]) [2,3,4]
iex> MerklePatriciaTree.ListHelper.get_postfix([1,2,3,4], [0,1]) nil
iex> MerklePatriciaTree.ListHelper.get_postfix([1,2,3,4], []) [1,2,3,4]
iex> MerklePatriciaTree.ListHelper.get_postfix([1,2], [1,2,3]) nil
iex> MerklePatriciaTree.ListHelper.get_postfix([], []) []
overlap([integer], [integer]) :: {[integer], [integer], [integer]}
Returns the overlap of two lists in terms of a shared prefix, then the relative postfixes
Examples
iex> MerklePatriciaTree.ListHelper.overlap([1,2,3], [1,2]) {[1,2],[3],[]}
iex> MerklePatriciaTree.ListHelper.overlap([1,2,3], [1,2,3,4]) {[1,2,3],[],[4]}
iex> MerklePatriciaTree.ListHelper.overlap([1,2,3], [2,3,4]) {[],[1,2,3],[2,3,4]}
iex> MerklePatriciaTree.ListHelper.overlap([], [2,3,4]) {[],[],[2,3,4]}
iex> MerklePatriciaTree.ListHelper.overlap([1,2,3], []) {[],[1,2,3],[]}
iex> MerklePatriciaTree.ListHelper.overlap([15, 10, 5, 11], [15, 11, 1, 14]) {[15], [10, 5, 11], [11, 1, 14]}