spacesaving v0.0.3 Spacesaving
Summary
Functions
Initialize the state
Merge two states together, adding the counts for keys in both counters. The new state will be the minimum of the two states’ sizes
Add the item, which should be an atom or string to the state
Get the top k counts as a descending sorted key list
Types
Functions
Specs
init(integer) :: counter
Initialize the state
Examples
iex> Spacesaving.init(2)
{%{}, 2}
Merge two states together, adding the counts for keys in both counters. The new state will be the minimum of the two states’ sizes.
Examples
iex> Spacesaving.merge({%{foo: 3, baz: 2}, 2}, {%{foo: 3, baz: 2}, 2})
{%{foo: 6, baz: 4}, 2}
iex> Spacesaving.merge({%{foo: 3, bar: 1}, 2}, {%{foo: 3, baz: 2}, 2})
{%{foo: 6, baz: 2}, 2}
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}