Compiled match specifications for ETS queries.
This module provides helper functions to create and compile match specs for common ETS query patterns. Compiled match specs can be reused across multiple queries for better performance.
Why use match specs?
:ets.match/2and:ets.match_object/2parse the pattern every time:ets.select/2with a compiled match spec skips parsing- For repeated queries, compiled specs reduce CPU overhead
Summary
Functions
Create a match spec to get all records.
Create a match spec for deletion.
Recursively extract capture variables (:"$1", :"$2", ...) from a match
pattern, deduplicate them, and sort them numerically by variable index.
Create a match spec for :ets.match/2 style queries.
Create a match spec for :ets.match_object/2 style queries.
Run a match spec against a table.
Run a match spec for deletion.
Create a match spec with a guard condition.
Types
Functions
@spec all_records() :: match_spec()
Create a match spec to get all records.
@spec compile(match_spec()) :: :ets.comp_match_spec() | match_spec()
@spec delete_match(tuple() | atom()) :: match_spec()
Create a match spec for deletion.
Recursively extract capture variables (:"$1", :"$2", ...) from a match
pattern, deduplicate them, and sort them numerically by variable index.
Supports capture variables at any nesting depth inside tuples and lists, so
patterns like {{:kv, :"$1"}, :"$2"} or {:rec, :"$2", :"$1"} work
correctly. The returned list is sorted by variable number so the output
binding list is always [b1, b2, ...] in numerical order.
@spec match(tuple() | atom(), [term()]) :: match_spec()
Create a match spec for :ets.match/2 style queries.
Returns a match spec that, when used with :ets.select/2, returns
a list of binding lists (like :ets.match/2).
@spec match_object(tuple() | atom()) :: match_spec()
Create a match spec for :ets.match_object/2 style queries.
@spec select(atom() | :ets.tid(), :ets.comp_match_spec() | match_spec()) :: [term()]
Run a match spec against a table.
@spec select_delete(atom() | :ets.tid(), :ets.comp_match_spec() | match_spec()) :: non_neg_integer()
Run a match spec for deletion.
@spec with_guard(tuple() | atom(), [tuple()], [term()]) :: match_spec()
Create a match spec with a guard condition.