huffman v1.2.0 Huffman.Tree View Source

Link to this section Summary

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

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

Link to this section 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.

Link to this function to_map(tree, by \\ :codes) View Source

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.