barrel_ngram_verify (barrel_ngram v0.9.0)

View Source

Windowed literal and regex verification.

A planner candidate match start is necessary, never sufficient. windowed/4 confirms a literal candidate by reading just byte_size(Literal) bytes at its start; windowed_regex/7 reads the window barrel_ngram_planner:regex_plan/2 computed around a chosen anchor and re-runs the pattern over that slice. Both are case-sensitive only -- phase-2 sampling is itself case-sensitive, so a caseless query never reaches this module.

Both reduce to the same non-overlapping matches a plain left-to-right scan (binary:matches/2, re:runglobal) reports: two independently distance-checked candidates can be real but overlapping matches ("aaa" at both offset 0 and 1 of "aaaa"), and without the reduction this module would report both, diverging from every other lane. See non_overlapping/1.

Summary

Functions

Spans reduced to the same leftmost-greedy non-overlapping set a left-to-right scan produces: sorted by start, keep the earliest available span and skip anything starting before it ends.

The subset of Starts where Source's bytes for Key, read at that start for byte_size(Literal) bytes, equal Literal exactly. A failed read (deleted document, or a race) drops that candidate silently.

The real {Start, Length} matches of RE, found by reading only the window around each AnchorStart in AnchorStarts: [AnchorStart - PrefixMax, AnchorStart + AnchorLen + SuffixMax), clamped to [0, doc_size). Spans are translated back to absolute offsets and deduplicated (more than one anchor can rediscover the same match). A failed doc_size/pread (deleted document, or a race) drops that document or window silently.

Functions

non_overlapping(Spans)

-spec non_overlapping([{non_neg_integer(), non_neg_integer()}]) ->
                         [{non_neg_integer(), non_neg_integer()}].

Spans reduced to the same leftmost-greedy non-overlapping set a left-to-right scan produces: sorted by start, keep the earliest available span and skip anything starting before it ends.

windowed(Source, Key, Literal, Starts)

-spec windowed({module(), term()}, binary(), binary(), [non_neg_integer()]) -> [non_neg_integer()].

The subset of Starts where Source's bytes for Key, read at that start for byte_size(Literal) bytes, equal Literal exactly. A failed read (deleted document, or a race) drops that candidate silently.

windowed_regex(Source, Key, RE, PrefixMax, AnchorLen, SuffixMax, AnchorStarts)

The real {Start, Length} matches of RE, found by reading only the window around each AnchorStart in AnchorStarts: [AnchorStart - PrefixMax, AnchorStart + AnchorLen + SuffixMax), clamped to [0, doc_size). Spans are translated back to absolute offsets and deduplicated (more than one anchor can rediscover the same match). A failed doc_size/pread (deleted document, or a race) drops that document or window silently.