"Seen recently" as two Bloom filter generations.
Keys are added to the current generation and looked up in both. Rotating clears the older generation and makes it current, so a key is remembered for at least one full rotation period and at most two, in fixed memory and without per-key expiry.
Summary
Functions
Whether key was seen recently.
Creates a filter remembering capacity keys per generation.
Adds key unless it was seen recently. Returns true if it was new.
put_new/2 for a key hashed with Limen.Sketch.Bloom.hash/1 or
Limen.Sketch.Bloom.hash_once/1.
Forgets the older generation and starts a new one.
Types
@type t() :: %Limen.Sketch.RotatingBloom{ cursor: :atomics.atomics_ref(), generations: {Limen.Sketch.Bloom.t(), Limen.Sketch.Bloom.t()} }
Functions
Whether key was seen recently.
@spec new(pos_integer(), float()) :: t()
Creates a filter remembering capacity keys per generation.
Adds key unless it was seen recently. Returns true if it was new.
@spec put_new_hash(t(), Limen.Sketch.Bloom.hash()) :: boolean()
put_new/2 for a key hashed with Limen.Sketch.Bloom.hash/1 or
Limen.Sketch.Bloom.hash_once/1.
@spec rotate(t()) :: :ok
Forgets the older generation and starts a new one.