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

source

const MIN_SKIPS: u32 = 50u32

The minimum number of skip attempts to try before considering whether a prefilter is effective or not.

source

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.

source

pub(crate) fn new() -> PrefilterState

Create a fresh prefilter state.

source

fn update(&mut self, skipped: usize)

Update this state with the number of bytes skipped on the last invocation of the prefilter.

source

fn is_effective(&mut self) -> bool

Return true if and only if this state indicates that a prefilter is still effective.

source

fn is_inert(&self) -> bool

Returns true if the prefilter this state represents should no longer be used.

source

fn skips(&self) -> u32

Returns the total number of times the prefilter has been used.

Trait Implementations§

source§

impl Clone for PrefilterState

source§

fn clone(&self) -> PrefilterState

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PrefilterState

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Copy for PrefilterState

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.