talan v0.1.0 Talan.Counter View Source
Linear probabilistic counter implementation with concurrent accessibility, powered by :atomics module for cardinality estimation.
Cardinality is the count of unique elements.
For more info about linear probabilistic counting: linear probabilistic counting
Link to this section Summary
Functions
Returns the estimated cardinality for the given
%Talan.Counter{} struct.
Returns a new %Talan.Counter{} struct.
Hashes term and sets a bit to mark it has been seen.
Link to this section Types
t()
View Sourcet() :: %Talan.Counter{
atomics_ref: reference(),
filter_length: non_neg_integer(),
hash_function: function()
}
Link to this section Functions
Returns the estimated cardinality for the given
%Talan.Counter{} struct.
Examples
iex> c = Talan.Counter.new(10_000)
iex> c |> Talan.Counter.put(["you", :can, Hash, {"any", "elixir", "term"}])
iex> c |> Talan.Counter.put(["you", :can, Hash, {"any", "elixir", "term"}])
iex> c |> Talan.Counter.cardinality()
1
iex> c |> Talan.Counter.put("more")
iex> c |> Talan.Counter.cardinality()
2
new(expected_cardinality, options \\ [])
View Sourcenew(non_neg_integer(), list()) :: t()
Returns a new %Talan.Counter{} struct.
expected_cardinality is the max number of uniq items the counter will
handle with approx 1% of error rate.
Options
hash_function- defaults toMurmur.hash_x64_128/1
Examples
iex> c = Talan.Counter.new(10_000)
iex> c |> Talan.Counter.put(["you", :can, Hash, {"any", "elixir", "term"}])
iex> c |> Talan.Counter.put("more")
iex> c |> Talan.Counter.put("another")
iex> c |> Talan.Counter.cardinality()
3
Hashes term and sets a bit to mark it has been seen.
Doesn't store the term so it's space efficient.
Uses :atomics so it's mutable & highly concurrent.
Returns :ok.
Examples
iex> c = Talan.Counter.new(10_000)
iex> c |> Talan.Counter.put(["you", :can, Hash, {"any", "elixir", "term"}])
:ok