Struct regex_automata::dfa::remapper::IndexMapper

source ·
struct IndexMapper {
    stride2: usize,
}
Expand description

A simple type for mapping between state indices and state IDs.

The reason why this exists is because state IDs are “premultiplied.” That is, in order to get to the transitions for a particular state, one need only use the state ID as-is, instead of having to multiple it by transition table’s stride.

The downside of this is that it’s inconvenient to map between state IDs using a dense map, e.g., Vec. That’s because state IDs look like 0, 0+stride, 0+2*stride, 0+3*stride, etc., instead of 0, 1, 2, 3, etc.

Since our state IDs are premultiplied, we can convert back-and-forth between IDs and indices by simply unmultiplying the IDs and multiplying the indices.

Fields§

§stride2: usize

The power of 2 corresponding to the stride of the corresponding transition table. ‘id >> stride2’ de-multiplies an ID while ‘index << stride2’ pre-multiplies an index to an ID.

Implementations§

source§

impl IndexMapper

source

fn to_index(&self, id: StateID) -> usize

Convert a state ID to a state index.

source

fn to_state_id(&self, index: usize) -> StateID

Convert a state index to a state ID.

Trait Implementations§

source§

impl Debug for IndexMapper

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, 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.