Struct aho_corasick::util::alphabet::ByteClasses

source ·
pub(crate) struct ByteClasses([u8; 256]);
Expand description

A representation of byte oriented equivalence classes.

This is used in finite state machines to reduce the size of the transition table. This can have a particularly large impact not only on the total size of an FSM, but also on FSM build times because it reduces the number of transitions that need to be visited/set.

Tuple Fields§

§0: [u8; 256]

Implementations§

source§

impl ByteClasses

source

pub(crate) fn empty() -> ByteClasses

Creates a new set of equivalence classes where all bytes are mapped to the same class.

source

pub(crate) fn singletons() -> ByteClasses

Creates a new set of equivalence classes where each byte belongs to its own equivalence class.

source

pub(crate) fn set(&mut self, byte: u8, class: u8)

Set the equivalence class for the given byte.

source

pub(crate) fn get(&self, byte: u8) -> u8

Get the equivalence class for the given byte.

source

pub(crate) fn alphabet_len(&self) -> usize

Return the total number of elements in the alphabet represented by these equivalence classes. Equivalently, this returns the total number of equivalence classes.

source

pub(crate) fn stride2(&self) -> usize

Returns the stride, as a base-2 exponent, required for these equivalence classes.

The stride is always the smallest power of 2 that is greater than or equal to the alphabet length. This is done so that converting between state IDs and indices can be done with shifts alone, which is much faster than integer division. The “stride2” is the exponent. i.e., 2^stride2 = stride.

source

pub(crate) fn stride(&self) -> usize

Returns the stride for these equivalence classes, which corresponds to the smallest power of 2 greater than or equal to the number of equivalence classes.

source

pub(crate) fn is_singleton(&self) -> bool

Returns true if and only if every byte in this class maps to its own equivalence class. Equivalently, there are 257 equivalence classes and each class contains exactly one byte (plus the special EOI class).

source

pub(crate) fn iter(&self) -> ByteClassIter

Returns an iterator over all equivalence classes in this set.

source

pub(crate) fn elements(&self, class: u8) -> ByteClassElements<'_>

Returns an iterator of the bytes in the given equivalence class.

source

fn element_ranges(&self, class: u8) -> ByteClassElementRanges<'_>

Returns an iterator of byte ranges in the given equivalence class.

That is, a sequence of contiguous ranges are returned. Typically, every class maps to a single contiguous range.

Trait Implementations§

source§

impl Clone for ByteClasses

source§

fn clone(&self) -> ByteClasses

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 ByteClasses

source§

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

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

impl Copy for ByteClasses

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