pub(crate) struct Teddy {
searcher: Searcher,
anchored_ac: DFA,
minimum_len: usize,
}
Fields§
§searcher: Searcher
The actual Teddy searcher.
Technically, it’s possible that Teddy doesn’t actually get used, since Teddy does require its haystack to at least be of a certain size (usually around the size of whatever vector is being used, so ~16 or ~32 bytes). For haystacks shorter than that, the implementation currently uses Rabin-Karp.
anchored_ac: DFA
When running an anchored search, the packed searcher can’t handle it so we defer to Aho-Corasick itself. Kind of sad, but changing the packed searchers to support anchored search would be difficult at worst and annoying at best. Since packed searchers only apply to small numbers of literals, we content ourselves that this is not much of an added cost. (That packed searchers only work with a small number of literals is also why we use a DFA here. Otherwise, the memory usage of a DFA would likely be unacceptable.)
minimum_len: usize
The length of the smallest literal we look for.
We use this as a heuristic to figure out whether this will be “fast” or not. Generally, the longer the better, because longer needles are more discriminating and thus reduce false positive rate.
Implementations§
Trait Implementations§
source§impl PrefilterI for Teddy
impl PrefilterI for Teddy
source§fn find(&self, haystack: &[u8], span: Span) -> Option<Span>
fn find(&self, haystack: &[u8], span: Span) -> Option<Span>
haystack[span.start..end]
and return a matching
span if one exists. Read moresource§fn prefix(&self, haystack: &[u8], span: Span) -> Option<Span>
fn prefix(&self, haystack: &[u8], span: Span) -> Option<Span>
haystack[span.start..span.end]
if
the prefilter matches. Read moresource§fn memory_usage(&self) -> usize
fn memory_usage(&self) -> usize
source§fn is_fast(&self) -> bool
fn is_fast(&self) -> bool
Prefilter::is_fast
for more details.