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 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<Self, DfaWireError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, 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 more