Module nfa

Provides direct access to NFA implementations of Aho-Corasick.

The principle characteristic of an NFA in this crate is that it may transition through multiple states per byte of haystack. In Aho-Corasick parlance, NFAs follow failure transitions during a search. In contrast, a DFA pre-computes all failure transitions during compilation at the expense of a much bigger memory footprint.

Currently, there are two NFA implementations provided: noncontiguous and contiguous. The names reflect their internal representation, and consequently, the trade offs associated with them:

When given the choice between these two, you almost always want to pick a contiguous NFA. It takes only a little longer to build, but both its memory usage and search speed are typically much better than a noncontiguous NFA. A noncontiguous NFA is useful when prioritizing build times, or when there are so many patterns that a contiguous NFA could not be built. (Currently, because of both memory and search speed improvements, a contiguous NFA has a smaller internal limit on the total number of NFA states it can represent. But you would likely need to have hundreds of thousands or even millions of patterns before you hit this limit.)

Modules