pub struct CompiledDfa {
pub transitions: Vec<u32>,
pub accept: Vec<u32>,
pub state_count: u32,
pub max_pattern_len: u32,
pub output_offsets: Vec<u32>,
pub output_records: Vec<u32>,
}Expand description
Compiled DFA ready to be uploaded to a GPU buffer.
Fields§
§transitions: Vec<u32>transitions[state * 256 + byte] = next_state. Length =
state_count * 256.
accept: Vec<u32>accept[state] = pattern_id + 1 when state accepts, else 0.
Length = state_count.
state_count: u32Number of states in the automaton (>= 1; state 0 is root).
max_pattern_len: u32Longest pattern length in bytes. Scanners can limit each per-position replay to this suffix window without changing Aho-Corasick semantics.
output_offsets: Vec<u32>output_offsets[state] = start index in output_records for
state. Length = state_count + 1. The last element is the
total length of output_records.
output_records: Vec<u32>Flat array of pattern ids. Each state s owns the slice
output_records[output_offsets[s]..output_offsets[s+1]].
These are all patterns that match at s (including via
failure links), not just the single accept[state] id.
Implementations§
Source§impl CompiledDfa
impl CompiledDfa
Sourcepub fn empty() -> CompiledDfa
pub fn empty() -> CompiledDfa
Empty DFA with a single rejecting root state.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, DfaWireError>
pub fn to_bytes(&self) -> Result<Vec<u8>, DfaWireError>
Serialize this DFA into a self-describing little-endian binary
blob suitable for on-disk caching. Stable layout under
DFA_WIRE_VERSION. Pure data, no allocator-dependent state.
Layout:
- 4 bytes: magic
b"VDFA" - 4 bytes: version (LE u32)
- 4 bytes: state_count (LE u32)
- 4 bytes: max_pattern_len (LE u32)
- 4 bytes: transitions length in u32 words (LE u32)
- 4 bytes: accept length in u32 words (LE u32)
- 4 bytes: output_offsets length in u32 words (LE u32)
- 4 bytes: output_records length in u32 words (LE u32)
- transitions data (state_count * 256 * 4 bytes)
- accept data (state_count * 4 bytes)
- output_offsets data ((state_count + 1) * 4 bytes)
- output_records data (variable * 4 bytes)
Total size is O(state_count) bytes; ~1 MiB per 1k states.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<CompiledDfa, DfaWireError>
pub fn from_bytes(bytes: &[u8]) -> Result<CompiledDfa, DfaWireError>
Decode a CompiledDfa from a blob produced by Self::to_bytes.
§Errors
Returns DfaWireError for truncation, magic mismatch, version
drift, or shape inconsistencies. A VersionMismatch is the
expected signal to invalidate an on-disk cache and recompile.
Trait Implementations§
Source§impl Clone for CompiledDfa
impl Clone for CompiledDfa
Source§fn clone(&self) -> CompiledDfa
fn clone(&self) -> CompiledDfa
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CompiledDfa
impl RefUnwindSafe for CompiledDfa
impl Send for CompiledDfa
impl Sync for CompiledDfa
impl Unpin for CompiledDfa
impl UnsafeUnpin for CompiledDfa
impl UnwindSafe for CompiledDfa
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§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more