Struct memchr::memmem::searcher::PrefilterState
source · pub(crate) struct PrefilterState {
skips: u32,
skipped: u32,
}
Expand description
PrefilterState tracks state associated with the effectiveness of a prefilter. It is used to track how many bytes, on average, are skipped by the prefilter. If this average dips below a certain threshold over time, then the state renders the prefilter inert and stops using it.
A prefilter state should be created for each search. (Where creating an
iterator is treated as a single search.) A prefilter state should only be
created from a Freqy
. e.g., An inert Freqy
will produce an inert
PrefilterState
.
Fields§
§skips: u32
The number of skips that has been executed. This is always 1 greater than the actual number of skips. The special sentinel value of 0 indicates that the prefilter is inert. This is useful to avoid additional checks to determine whether the prefilter is still “effective.” Once a prefilter becomes inert, it should no longer be used (according to our heuristics).
skipped: u32
The total number of bytes that have been skipped.
Implementations§
source§impl PrefilterState
impl PrefilterState
sourceconst MIN_SKIPS: u32 = 50u32
const MIN_SKIPS: u32 = 50u32
The minimum number of skip attempts to try before considering whether a prefilter is effective or not.
sourceconst MIN_SKIP_BYTES: u32 = 8u32
const MIN_SKIP_BYTES: u32 = 8u32
The minimum amount of bytes that skipping must average.
This value was chosen based on varying it and checking the microbenchmarks. In particular, this can impact the pathological/repeated-{huge,small} benchmarks quite a bit if it’s set too low.
sourcepub(crate) fn new() -> PrefilterState
pub(crate) fn new() -> PrefilterState
Create a fresh prefilter state.
sourcefn update(&mut self, skipped: usize)
fn update(&mut self, skipped: usize)
Update this state with the number of bytes skipped on the last invocation of the prefilter.
sourcefn is_effective(&mut self) -> bool
fn is_effective(&mut self) -> bool
Return true if and only if this state indicates that a prefilter is still effective.
Trait Implementations§
source§impl Clone for PrefilterState
impl Clone for PrefilterState
source§fn clone(&self) -> PrefilterState
fn clone(&self) -> PrefilterState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PrefilterState
impl Debug for PrefilterState
impl Copy for PrefilterState
Auto Trait Implementations§
impl Freeze for PrefilterState
impl RefUnwindSafe for PrefilterState
impl Send for PrefilterState
impl Sync for PrefilterState
impl Unpin for PrefilterState
impl UnwindSafe for PrefilterState
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)