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
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
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>>]
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>>}