Struct regex::literal::FreqyPacked [−][src]
pub struct FreqyPacked { pat: Vec<u8>, char_len: usize, rare1: u8, rare1i: usize, rare2: u8, rare2i: usize, }
Provides an implementation of fast subtring search using frequency analysis.
memchr is so fast that we do everything we can to keep the loop in memchr for as long as possible. The easiest way to do this is to intelligently pick the byte to send to memchr. The best byte is the byte that occurs least frequently in the haystack. Since doing frequency analysis on the haystack is far too expensive, we compute a set of fixed frequencies up front and hard code them in src/freqs.rs. Frequency analysis is done via scripts/frequencies.py.
Fields
pat: Vec<u8>
The pattern.
char_len: usize
The number of Unicode characters in the pattern. This is useful for determining the effective length of a pattern when deciding which optimizations to perform. A trailing incomplete UTF-8 sequence counts as one character.
rare1: u8
The rarest byte in the pattern, according to pre-computed frequency analysis.
rare1i: usize
The offset of the rarest byte in pat
.
rare2: u8
The second rarest byte in the pattern, according to pre-computed frequency analysis. (This may be equivalent to the rarest byte.)
The second rarest byte is used as a type of guard for quickly detecting a mismatch after memchr locates an instance of the rarest byte. This is a hedge against pathological cases where the pre-computed frequency analysis may be off. (But of course, does not prevent all pathological cases.)
rare2i: usize
The offset of the second rarest byte in pat
.
Methods
impl FreqyPacked
[src]
impl FreqyPacked
fn new(pat: Vec<u8>) -> FreqyPacked
[src]
fn new(pat: Vec<u8>) -> FreqyPacked
fn empty() -> FreqyPacked
[src]
fn empty() -> FreqyPacked
pub fn find(&self, haystack: &[u8]) -> Option<usize>
[src]
pub fn find(&self, haystack: &[u8]) -> Option<usize>
pub fn is_suffix(&self, text: &[u8]) -> bool
[src]
pub fn is_suffix(&self, text: &[u8]) -> bool
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
pub fn char_len(&self) -> usize
[src]
pub fn char_len(&self) -> usize
fn approximate_size(&self) -> usize
[src]
fn approximate_size(&self) -> usize
Trait Implementations
impl Clone for FreqyPacked
[src]
impl Clone for FreqyPacked
fn clone(&self) -> FreqyPacked
[src]
fn clone(&self) -> FreqyPacked
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for FreqyPacked
[src]
impl Debug for FreqyPacked
Auto Trait Implementations
impl Send for FreqyPacked
impl Send for FreqyPacked
impl Sync for FreqyPacked
impl Sync for FreqyPacked