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
impl ByteClasses
sourcepub(crate) fn empty() -> ByteClasses
pub(crate) fn empty() -> ByteClasses
Creates a new set of equivalence classes where all bytes are mapped to the same class.
sourcepub(crate) fn singletons() -> ByteClasses
pub(crate) fn singletons() -> ByteClasses
Creates a new set of equivalence classes where each byte belongs to its own equivalence class.
sourcepub(crate) fn set(&mut self, byte: u8, class: u8)
pub(crate) fn set(&mut self, byte: u8, class: u8)
Set the equivalence class for the given byte.
sourcepub(crate) fn alphabet_len(&self) -> usize
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.
sourcepub(crate) fn stride2(&self) -> usize
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
.
sourcepub(crate) fn stride(&self) -> usize
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.
sourcepub(crate) fn is_singleton(&self) -> bool
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).
sourcepub(crate) fn iter(&self) -> ByteClassIter ⓘ
pub(crate) fn iter(&self) -> ByteClassIter ⓘ
Returns an iterator over all equivalence classes in this set.
sourcepub(crate) fn elements(&self, class: u8) -> ByteClassElements<'_> ⓘ
pub(crate) fn elements(&self, class: u8) -> ByteClassElements<'_> ⓘ
Returns an iterator of the bytes in the given equivalence class.
sourcefn element_ranges(&self, class: u8) -> ByteClassElementRanges<'_> ⓘ
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
impl Clone for ByteClasses
source§fn clone(&self) -> ByteClasses
fn clone(&self) -> ByteClasses
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ByteClasses
impl Debug for ByteClasses
impl Copy for ByteClasses
Auto Trait Implementations§
impl Freeze for ByteClasses
impl RefUnwindSafe for ByteClasses
impl Send for ByteClasses
impl Sync for ByteClasses
impl Unpin for ByteClasses
impl UnwindSafe for ByteClasses
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)