regex_automata::sparse

Struct ByteClass

Source
pub struct ByteClass<T: AsRef<[u8]>, S: StateID = usize>(/* private fields */);
Expand description

A sparse DFA that shrinks its alphabet.

Alphabet shrinking is achieved by using a set of equivalence classes instead of using all possible byte values. Any two bytes belong to the same equivalence class if and only if they can be used interchangeably anywhere in the DFA while never discriminating between a match and a non-match.

Unlike dense DFAs, sparse DFAs do not tend to benefit nearly as much from using byte classes. In some cases, using byte classes can even marginally increase the size of a sparse DFA’s transition table. The reason for this is that a sparse DFA already compacts each state’s transitions separate from whether byte classes are used.

Generally, it isn’t necessary to use this type directly, since a SparseDFA can be used for searching directly. One possible reason why one might want to use this type directly is if you are implementing your own search routines by walking a DFA’s transitions directly. In that case, you’ll want to use this type (or any of the other DFA variant types) directly, since they implement next_state more efficiently.

Trait Implementations§

Source§

impl<T: Clone + AsRef<[u8]>, S: Clone + StateID> Clone for ByteClass<T, S>

Source§

fn clone(&self) -> ByteClass<T, S>

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<T: AsRef<[u8]>, S: StateID> DFA for ByteClass<T, S>

Source§

type ID = S

The representation used for state identifiers in this DFA. Read more
Source§

fn start_state(&self) -> S

Return the identifier of this DFA’s start state.
Source§

fn is_match_state(&self, id: S) -> bool

Returns true if and only if the given identifier corresponds to a match state.
Source§

fn is_dead_state(&self, id: S) -> bool

Returns true if and only if the given identifier corresponds to a dead state. When a DFA enters a dead state, it is impossible to leave and thus can never lead to a match.
Source§

fn is_match_or_dead_state(&self, id: S) -> bool

Returns true if and only if the given identifier corresponds to either a dead state or a match state, such that one of is_match_state(id) or is_dead_state(id) must return true. Read more
Source§

fn is_anchored(&self) -> bool

Returns true if and only if this DFA is anchored. Read more
Source§

fn next_state(&self, current: S, input: u8) -> S

Given the current state that this DFA is in and the next input byte, this method returns the identifier of the next state. The identifier returned is always valid, but it may correspond to a dead state.
Source§

unsafe fn next_state_unchecked(&self, current: S, input: u8) -> S

Like next_state, but its implementation may look up the next state without memory safety checks such as bounds checks. As such, callers must ensure that the given identifier corresponds to a valid DFA state. Implementors must, in turn, ensure that this routine is safe for all valid state identifiers and for all possible u8 values.
Source§

fn is_match(&self, bytes: &[u8]) -> bool

Returns true if and only if the given bytes match this DFA. Read more
Source§

fn shortest_match(&self, bytes: &[u8]) -> Option<usize>

Returns the first position at which a match is found. Read more
Source§

fn find(&self, bytes: &[u8]) -> Option<usize>

Returns the end offset of the longest match. If no match exists, then None is returned. Read more
Source§

fn rfind(&self, bytes: &[u8]) -> Option<usize>

Returns the start offset of the longest match in reverse, by searching from the end of the input towards the start of the input. If no match exists, then None is returned. In other words, this has the same match semantics as find, but in reverse. Read more
Source§

fn is_match_at(&self, bytes: &[u8], start: usize) -> bool

Returns the same as is_match, but starts the search at the given offset. Read more
Source§

fn shortest_match_at(&self, bytes: &[u8], start: usize) -> Option<usize>

Returns the same as shortest_match, but starts the search at the given offset. Read more
Source§

fn find_at(&self, bytes: &[u8], start: usize) -> Option<usize>

Returns the same as find, but starts the search at the given offset. Read more
Source§

fn rfind_at(&self, bytes: &[u8], start: usize) -> Option<usize>

Returns the same as rfind, but starts the search at the given offset. Read more
Source§

impl<T: Debug + AsRef<[u8]>, S: Debug + StateID> Debug for ByteClass<T, S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, S> Freeze for ByteClass<T, S>
where S: Freeze, T: Freeze,

§

impl<T, S> RefUnwindSafe for ByteClass<T, S>

§

impl<T, S> Send for ByteClass<T, S>
where S: Send, T: Send,

§

impl<T, S> Sync for ByteClass<T, S>
where S: Sync, T: Sync,

§

impl<T, S> Unpin for ByteClass<T, S>
where S: Unpin, T: Unpin,

§

impl<T, S> UnwindSafe for ByteClass<T, S>
where S: UnwindSafe, T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

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

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.