Struct regex_automata::nfa::thompson::backtrack::Visited

source ·
struct Visited {
    bitset: Vec<usize>,
    stride: usize,
}
Expand description

A bitset that keeps track of whether a particular (StateID, offset) has been considered during backtracking. If it has already been visited, then backtracking skips it. This is what gives backtracking its “bound.”

Fields§

§bitset: Vec<usize>

The actual underlying bitset. Each element in the bitset corresponds to a particular (StateID, offset) pair. States correspond to the rows and the offsets correspond to the columns.

If our underlying NFA has N states and the haystack we’re searching has M bytes, then we have N*(M+1) entries in our bitset table. The M+1 occurs because our matches are delayed by one byte (to support look-around), and so we need to handle the end position itself rather than stopping just before the end. (If there is no end position, then it’s treated as “end-of-input,” which is matched by things like ‘$’.)

Given BITS=N*(M+1), we wind up with div_ceil(BITS, sizeof(usize)) blocks.

We use ‘usize’ to represent our blocks because it makes some of the arithmetic in ‘insert’ a bit nicer. For example, if we used ‘u32’ for our block, we’d either need to cast u32s to usizes or usizes to u32s.

§stride: usize

The stride represents one plus length of the haystack we’re searching (as described above). The stride must be initialized for each search.

Implementations§

source§

impl Visited

source

const BLOCK_SIZE: usize = 64usize

The size of each block, in bits.

source

fn new(re: &BoundedBacktracker) -> Visited

Create a new visited set for the given backtracker.

The set is ready to use, but must be setup at the beginning of each search by calling setup_search.

source

fn insert(&mut self, sid: StateID, at: usize) -> bool

Insert the given (StateID, offset) pair into this set. If it already exists, then this is a no-op and it returns false. Otherwise this returns true.

source

fn reset(&mut self, _: &BoundedBacktracker)

Reset this visited set to work with the given bounded backtracker.

Setup this visited set to work for a search using the given NFA and input configuration. The NFA must be the same NFA used by the BoundedBacktracker given to Visited::reset. Failing to call this might result in panics or silently incorrect search behavior.

source

fn memory_usage(&self) -> usize

Return the heap memory usage, in bytes, of this visited set.

Trait Implementations§

source§

impl Clone for Visited

source§

fn clone(&self) -> Visited

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 Visited

source§

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

Formats the value using the given formatter. Read more

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.