Struct regex_automata::dfa::remapper::Remapper

source ·
pub(super) struct Remapper {
    map: Vec<StateID>,
    idxmap: IndexMapper,
}
Expand description

Remapper is an abstraction the manages the remapping of state IDs in a finite state machine. This is useful when one wants to shuffle states into different positions in the machine.

One of the key complexities this manages is the ability to correctly move one state multiple times.

Once shuffling is complete, remap must be called, which will rewrite all pertinent transitions to updated state IDs. Neglecting to call remap will almost certainly result in a corrupt machine.

Fields§

§map: Vec<StateID>

A map from the index of a state to its pre-multiplied identifier.

When a state is swapped with another, then their corresponding locations in this map are also swapped. Thus, its new position will still point to its old pre-multiplied StateID.

While there is a bit more to it, this then allows us to rewrite the state IDs in a DFA’s transition table in a single pass. This is done by iterating over every ID in this map, then iterating over each transition for the state at that ID and re-mapping the transition from old_id to map[dfa.to_index(old_id)]. That is, we find the position in this map where old_id started, and set it to where it ended up after all swaps have been completed.

§idxmap: IndexMapper

A mapper from state index to state ID (and back).

Implementations§

source§

impl Remapper

source

pub(super) fn new(r: &impl Remappable) -> Remapper

Create a new remapper from the given remappable implementation. The remapper can then be used to swap states. The remappable value given here must the same one given to swap and remap.

source

pub(super) fn swap( &mut self, r: &mut impl Remappable, id1: StateID, id2: StateID, )

Swap two states. Once this is called, callers must follow through to call remap, or else it’s possible for the underlying remappable value to be in a corrupt state.

source

pub(super) fn remap(self, r: &mut impl Remappable)

Complete the remapping process by rewriting all state IDs in the remappable value according to the swaps performed.

Trait Implementations§

source§

impl Debug for Remapper

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

source§

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

source§

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.