merkle_patricia_tree v0.2.8 MerklePatriciaTree.Trie.Inspector

A simple module to inspect and print the structure of tries.

Link to this section Summary

Functions

Returns all keys from a trie.

Returns all values from a trie.

Helper function to print an instruction message.

Prints a visual depiction of a trie, returns trie itself.

Link to this section Functions

Link to this function

all_keys(trie)

all_keys(MerklePatriciaTree.Trie.t()) :: [binary()]

Returns all keys from a trie.

Note: this simply calls all_values/1 and returns the first value of all tuples.

Examples

iex> MerklePatriciaTree.Trie.new(MerklePatriciaTree.Test.random_ets_db())
...>   |> MerklePatriciaTree.Trie.update("type", "fighter")
...>   |> MerklePatriciaTree.Trie.update("name", "bob")
...>   |> MerklePatriciaTree.Trie.update("nationality", "usa")
...>   |> MerklePatriciaTree.Trie.update("nato", "strong")
...>   |> MerklePatriciaTree.Trie.update((for x <- 1..100, into: <<>>, do: <<x::8>>), (for x <- 1..100, into: <<>>, do: <<x*2::8>>))
...>   |> MerklePatriciaTree.Trie.Inspector.all_keys()
[
  (for x <- 1..100, into: <<>>, do: <<x::8>>),
  "name",
  "nationality",
  "nato",
  "type",
]
Link to this function

all_values(trie)

all_values(MerklePatriciaTree.Trie.t()) :: [{binary(), binary()}]

Returns all values from a trie.

Examples

iex> MerklePatriciaTree.Trie.new(MerklePatriciaTree.Test.random_ets_db())
...>   |> MerklePatriciaTree.Trie.update("type", "fighter")
...>   |> MerklePatriciaTree.Trie.update("name", "bob")
...>   |> MerklePatriciaTree.Trie.update("nationality", "usa")
...>   |> MerklePatriciaTree.Trie.update("nato", "strong")
...>   |> MerklePatriciaTree.Trie.update((for x <- 1..100, into: <<>>, do: <<x::8>>), (for x <- 1..100, into: <<>>, do: <<x*2::8>>))
...>   |> MerklePatriciaTree.Trie.Inspector.all_values()
[
  {(for x <- 1..100, into: <<>>, do: <<x::8>>), (for x <- 1..100, into: <<>>, do: <<x*2::8>>)},
  {"name", "bob"},
  {"nationality", "usa"},
  {"nato", "strong"},
  {"type", "fighter"},
]
Link to this function

inspect(msg, prefix)

Helper function to print an instruction message.

Prints a visual depiction of a trie, returns trie itself.

TODO: Test, possibly.