pub struct Automaton { /* private fields */ }Expand description
Aho-Corasick automaton using daachorse’s double-array implementation.
This wrapper provides the same interface as the previous FrozenNfa but with significantly smaller memory footprint and serialization support.
Implementations§
Source§impl Automaton
impl Automaton
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create a new empty automaton.
Since daachorse requires at least one non-empty pattern, we use a dummy pattern that will never match in practice (a unique byte sequence).
Sourcepub fn build(patterns: &[&[u8]]) -> Self
pub fn build(patterns: &[&[u8]]) -> Self
Build an automaton from patterns.
Each pattern is a byte slice. Patterns are assigned IDs in order.
Sourcepub fn find_overlapping_iter(&self, haystack: &[u8]) -> FindOverlappingIter ⓘ
pub fn find_overlapping_iter(&self, haystack: &[u8]) -> FindOverlappingIter ⓘ
Find all overlapping matches in the haystack.
Returns an iterator that yields all matches found in the haystack, including overlapping matches. The matches are yielded in order of their end position.
Important: This filters matches to only those starting at even byte positions (token boundaries). Each token is encoded as 2 bytes, so matches starting at odd byte positions would span token boundaries.
Sourcepub fn deserialize_unchecked(bytes: &[u8]) -> Self
pub fn deserialize_unchecked(bytes: &[u8]) -> Self
Deserialize an automaton from bytes.
§Safety
The bytes must be valid serialized data from the underlying daachorse automaton.
Sourcepub fn num_states(&self) -> usize
pub fn num_states(&self) -> usize
Get the number of states in the automaton.
Sourcepub fn heap_bytes(&self) -> usize
pub fn heap_bytes(&self) -> usize
Get the memory usage in bytes.
Sourcepub fn serialize_bytes(&self) -> Vec<u8> ⓘ
pub fn serialize_bytes(&self) -> Vec<u8> ⓘ
Serialize the automaton to a byte vector.
Trait Implementations§
Source§impl ArchiveWith<Automaton> for AsBytes
impl ArchiveWith<Automaton> for AsBytes
Auto Trait Implementations§
impl Freeze for Automaton
impl RefUnwindSafe for Automaton
impl Send for Automaton
impl Sync for Automaton
impl Unpin for Automaton
impl UnsafeUnpin for Automaton
impl UnwindSafe for Automaton
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.