esdb_filter_nif (reckon_db v1.6.0)

View Source

Optimized pattern matching and filtering operations for reckon-db.

This module provides high-performance pattern matching implementations:

  • Wildcard matching: Fast * and ? pattern matching
  • Regex matching: Compiled regex pattern matching
  • Prefix/Suffix matching: Optimized start/end checks
  • Batch filtering: Filter lists by patterns efficiently

The mode is automatically detected at startup based on whether the NIF library is available. Community edition users (hex.pm) will always use the Erlang fallbacks, which provide identical functionality.

Wildcard Patterns

Wildcards supported:

  • * matches any sequence of characters (including empty)
  • ? matches any single character

Usage

  %% Check if a stream matches a pattern
  true = esdb_filter_nif:wildcard_match(<<"orders-123">>, <<"orders-*">>).
 
  %% Filter streams by pattern
  Matching = esdb_filter_nif:filter_by_wildcard(Streams, <<"user-*">>).
 
  %% Check which mode is active
  nif = esdb_filter_nif:implementation().  %% Enterprise
  erlang = esdb_filter_nif:implementation(). %% Community

Summary

Functions

Count items matching a wildcard pattern.

Filter a list of binaries by prefix.

Filter a list of binaries by regex pattern.

Filter a list of binaries by suffix.

Filter a list of binaries by wildcard pattern.

Check if a string has a specific prefix.

Check if a string has a specific suffix.

Get the current implementation mode.

Check if the NIF is loaded (Enterprise mode).

Validate that a pattern is a valid regex.

Return indices of items matching a wildcard pattern.

Check if a string matches a regex pattern.

Check if a string matches a wildcard pattern.

Convert a wildcard pattern to a regex pattern.

Functions

count_matches(Items, Pattern)

-spec count_matches(Items :: [binary()], Pattern :: binary()) -> non_neg_integer().

Count items matching a wildcard pattern.

filter_by_prefix(Items, Prefix)

-spec filter_by_prefix(Items :: [binary()], Prefix :: binary()) -> [binary()].

Filter a list of binaries by prefix.

filter_by_regex(Items, RegexPattern)

-spec filter_by_regex(Items :: [binary()], RegexPattern :: binary()) -> [binary()].

Filter a list of binaries by regex pattern.

filter_by_suffix(Items, Suffix)

-spec filter_by_suffix(Items :: [binary()], Suffix :: binary()) -> [binary()].

Filter a list of binaries by suffix.

filter_by_wildcard(Items, Pattern)

-spec filter_by_wildcard(Items :: [binary()], Pattern :: binary()) -> [binary()].

Filter a list of binaries by wildcard pattern.

has_prefix(Text, Prefix)

-spec has_prefix(Text :: binary(), Prefix :: binary()) -> boolean().

Check if a string has a specific prefix.

has_suffix(Text, Suffix)

-spec has_suffix(Text :: binary(), Suffix :: binary()) -> boolean().

Check if a string has a specific suffix.

implementation()

-spec implementation() -> nif | erlang.

Get the current implementation mode.

is_nif_loaded()

-spec is_nif_loaded() -> boolean().

Check if the NIF is loaded (Enterprise mode).

is_valid_regex(Pattern)

-spec is_valid_regex(Pattern :: binary()) -> boolean().

Validate that a pattern is a valid regex.

match_indices(Items, Pattern)

-spec match_indices(Items :: [binary()], Pattern :: binary()) -> [non_neg_integer()].

Return indices of items matching a wildcard pattern.

regex_match(Text, RegexPattern)

-spec regex_match(Text :: binary(), RegexPattern :: binary()) -> boolean().

Check if a string matches a regex pattern.

wildcard_match(Text, Pattern)

-spec wildcard_match(Text :: binary(), Pattern :: binary()) -> boolean().

Check if a string matches a wildcard pattern.

wildcard_to_regex(Pattern)

-spec wildcard_to_regex(Pattern :: binary()) -> binary().

Convert a wildcard pattern to a regex pattern.

Wildcards: - * matches any sequence of characters - ? matches any single character