LimitedMapSet (limited_map_set v0.1.0)
View SourceA bounded, processless version of MapSet that keeps insertion order (FIFO)
and evicts the oldest elements when reaching the given limit.
Combines MapSet (for fast membership) with :queue (for insertion order).
Summary
Functions
Clears all elements.
Removes a value if it exists.
Checks if the given value is in the set.
Creates an empty LimitedMapSet with a specified limit.
Creates a LimitedMapSet from a list of values with a specified limit.
Adds a new element to the set.
Returns the number of elements in the set.
Returns all elements as a list in insertion order (oldest → newest).
Types
Functions
Clears all elements.
Removes a value if it exists.
Checks if the given value is in the set.
@spec new(pos_integer()) :: t()
Creates an empty LimitedMapSet with a specified limit.
Examples
iex> LimitedMapSet.new(100)
%LimitedMapSet{limit: 100, size: 0}
@spec new(list(), pos_integer()) :: t()
Creates a LimitedMapSet from a list of values with a specified limit.
If the list exceeds the limit, the oldest items are trimmed.
Examples
iex> LimitedMapSet.new([1, 2, 3, 4], 3) |> LimitedMapSet.to_list()
[2, 3, 4]
Adds a new element to the set.
- If it already exists, returns the set unchanged.
- If full, evicts the oldest element (FIFO).
@spec size(t()) :: non_neg_integer()
Returns the number of elements in the set.
Returns all elements as a list in insertion order (oldest → newest).