Huffman.Tree
SourceSummary↑
build(list1, tree) | |
from_codes(codes) | Takes a list of codes and their corresponding bytes, rebuilding the tree ( without weights) |
get_key(tree, key_bits) | Gets a key based on its code. Returns the key, and the unused part of the supplied code |
insert(tree, code, key) | |
new(frequencies) | Creates a new huffman tree with the included frequencies
|
reduce(tree, acc, fun) | Calls the supplied function for each leaf node |
to_list(tree) | |
to_map(tree, by \\ :codes) | Returns a the tree as a map. By default, maps codes (the encoded bits) to keys (the byte it decodes into.) Optional second argument can give the inverse ( keys => codes) |
to_string(tree) | The string representation of a Huffman.Tree. Basically a map from codes to their decoded value |
Functions
Takes a list of codes and their corresponding bytes, rebuilding the tree ( without weights)
Gets a key based on its code. Returns the key, and the unused part of the supplied code.
iex> Huffman.Tree.new([{"a", 1}, {"b", 1}, {"c", 4}, {"x", 9}])
...> |> Huffman.Tree.get_key(<<0::1, 0::1, 1::1>>)
{"b", <<>>}
It returns the unused portion of the code as well since in decoding you aren’t always sure what the next code is going to be until you find the key that matches. This allows you to simply pass in the decoded part and it will return the first decoded key.
Creates a new huffman tree with the included frequencies
Huffman.Tree.new([{"a", 1}, {"b", 1}, {"c", 4}, {"x", 9}])
Calls the supplied function for each leaf node.
Returns a the tree as a map. By default, maps codes (the encoded bits) to keys (the byte it decodes into.) Optional second argument can give the inverse ( keys => codes)
The string representation of a Huffman.Tree. Basically a map from codes to their decoded value.