huffman v1.2.0 Huffman.Helpers View Source

Link to this section Summary

Functions

Counts the frequency of codepoints in a given binary

Returns all codepoints in the string. Optional second argument specifies the encoding (utf8, utf16, utf32), defaulting to :utf8

Returns the next codepoint in a String. Optional second argument specifies the encoding (utf8, utf16, utf32), defaulting to :utf8

Link to this section Functions

Link to this function binary_frequencies(bin, encoding \\ :utf8) View Source

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

Link to this function codepoints(binary, encoding \\ :utf8) View Source

Returns all codepoints in the string. Optional second argument specifies the encoding (utf8, utf16, utf32), defaulting to :utf8.

Examples

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>>]
Link to this function next_codepoint(bin, encoding \\ :utf8) View Source

Returns the next codepoint in a String. Optional second argument specifies the encoding (utf8, utf16, utf32), defaulting to :utf8.

Examples

iex> Huffman.Helpers.next_codepoint("olá")
{"o", "lá"}

iex> Huffman.Helpers.next_codepoint(<<"olá"::utf16>>, :utf16)
{<<0, 111>>, <<0, 108, 0, 225>>}

iex> Huffman.Helpers.next_codepoint(<<"olá"::utf32>>, :utf32)
{<<0, 0, 0, 111>>, <<0, 0, 0, 108, 0, 0, 0, 225>>}
Link to this function sort_frequencies(arg1, arg2) View Source