spacesaving v0.0.1 Spacesaving

Summary

Functions

Initialize the state

Add the item, which should be an atom or string to the state

Get the top k counts as a descending sorted key list

Functions

init(n)

Initialize the state

Examples

iex> Spacesaving.init(2)
{%{}, 2}
push(arg, item)

Add the item, which should be an atom or string to the state

Examples

iex> Spacesaving.init(2) |> Spacesaving.push(:foo) |> Spacesaving.push(:bar)
{%{foo: 1, bar: 1}, 2}
iex> Spacesaving.init(2) |> Spacesaving.push(:foo) |> Spacesaving.push(:foo) |> Spacesaving.push(:bar) |> Spacesaving.push(:baz)
{%{foo: 2, baz: 2}, 2}
top(arg, k)

Get the top k counts as a descending sorted key list

Examples

iex> {%{foo: 3, baz: 2}, 2} |> Spacesaving.top(2)
[foo: 3, baz: 2]
iex> {%{foo: 3, baz: 2}, 2} |> Spacesaving.top(1)
[foo: 3]