Documentation
¶
Overview ¶
Package matcher finds which of a fixed set of literals occur in a text, in a single pass.
Rules commonly gate an expensive regular expression behind a set of cheap literal checks: if none of the words a pattern requires appear, the pattern cannot match and need not run. Done naively that is one full scan of the content per literal — and the scans all run to completion precisely in the common case where nothing matches.
An Aho-Corasick automaton answers the whole question in one pass: O(n) in the text length regardless of how many literals are being searched for, after an O(total literal length) build that happens once at package initialisation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher is an Aho-Corasick automaton over a fixed literal set.
A Matcher is immutable once built and safe for concurrent use.
func New ¶
New builds an automaton for the given literals.
Literal IDs correspond to positions in the slice. Empty literals are skipped, since they would match everywhere and carry no information.
Matching is byte-exact: callers wanting case-insensitive behaviour should supply lowercase literals and lowercase the text.