Huffman.Helpers
SourceSummary↑
binary_frequencies(bin, encoding \\ :utf8) | Counts the frequency of codepoints in a given binary |
codepoints(binary, encoding) | Given a binary and its encoding, returns a list of codepoints as binaries |
inspect_bits(bits) | |
sort_frequencies(arg1, arg2) |
Functions
Counts the frequency of codepoints in a given binary.
Returns a list of tuples, the first element is the code point and the second is the number of occurences. The list is sorted first by the count, falling back to comparing the codepoints themselves.
iex> Huffman.Helpers.binary_frequencies("bobbing")
[{"g", 1}, {"i", 1}, {"n", 1}, {"o", 1}, {"b", 3}]
Defaults to utf8 but the optional second parameter can also be set to :utf16
or :utf32
Given a binary and its encoding, returns a list of codepoints as binaries
iex> Huffman.Helpers.codepoints(<<"boom"::utf8>>, :utf8)
[<<98>>, <<111>>, <<111>>, <<109>>]
iex> Huffman.Helpers.codepoints(<<"boom"::utf16>>, :utf16)
[<<0, 98>>, <<0, 111>>, <<0, 111>>, <<0, 109>>]
iex> Huffman.Helpers.codepoints(<<"boom"::utf32>>, :utf32)
[<<0, 0, 0, 98>>, <<0, 0, 0, 111>>, <<0, 0, 0, 111>>, <<0, 0, 0, 109>>]