LimitedMapSet (limited_map_set v0.1.0)

View Source

A 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

t()

@opaque t()

Functions

clear(limited_map_set)

@spec clear(t()) :: t()

Clears all elements.

delete(s, value)

@spec delete(t(), any()) :: t()

Removes a value if it exists.

member?(limited_map_set, value)

@spec member?(t(), any()) :: boolean()

Checks if the given value is in the set.

new(limit)

@spec new(pos_integer()) :: t()

Creates an empty LimitedMapSet with a specified limit.

Examples

iex> LimitedMapSet.new(100)
%LimitedMapSet{limit: 100, size: 0}

new(list, limit)

@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]

put(s, value)

@spec put(t(), any()) :: t()

Adds a new element to the set.

  • If it already exists, returns the set unchanged.
  • If full, evicts the oldest element (FIFO).

size(limited_map_set)

@spec size(t()) :: non_neg_integer()

Returns the number of elements in the set.

to_list(limited_map_set)

@spec to_list(t()) :: [any()]

Returns all elements as a list in insertion order (oldest → newest).