#[non_exhaustive]pub struct QueryDFA {
pub num_states: usize,
pub start_state: usize,
pub is_accepting: Vec<bool>,
pub transitions: Vec<Vec<Option<usize>>>,
pub alphabet: Vec<TransitionLabel>,
pub key_to_key_id: HashMap<Rc<String>, usize>,
pub range_to_range_id: Vec<(Range<usize>, usize)>,
pub case_insensitive: bool,
}Expand description
Represents a Deterministic Finite Automaton (DFA) for JSON queries. An important thing to note is that the alphabet depends on the query.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.num_states: usizeThe number of states in the DFA
start_state: usizeThe starting state of the DFA
is_accepting: Vec<bool>Bitmap of accepting states
transitions: Vec<Vec<Option<usize>>>Transition table: transitions[state][symbol_index] -> Option<next_state>
alphabet: Vec<TransitionLabel>Alphabet symbols for this DFA. The alphabet is necessarily finite and disjoint. The alphabet is determined from the input query.
key_to_key_id: HashMap<Rc<String>, usize>Mapping of field names to symbol indices in alphabet. Uses a reference
counter for the field name to avoid expensive clones. Any encountered
key while traversing that was not found from symbol extraction phase
of the query AST is lumped together with all “other” keys, which
corresponds to key ID 0.
range_to_range_id: Vec<(Range<usize>, usize)>Maps non-overlapping ranges of array indices to their corresponding symbol IDs in the DFA’s alphabet.
Each tuple (range, id) represents a range [range.start, range.end)
associated with a symbol ID, where the symbol is either a
TransitionLabel::Range or TransitionLabel::RangeFrom. Ranges are
constructed in DFABuilder::finalize_ranges to be disjoint and cover
the domain [0, usize::MAX].
Individual index accesses (e.g., Query::Index) are represented as
single-element ranges [i, i+1). Used by get_index_symbol_id to
resolve array indices to symbol IDs during DFA traversal.
case_insensitive: boolWhether fields are case-sensitive.
Implementations§
Source§impl QueryDFA
impl QueryDFA
Sourcepub fn from_query(query: &Query) -> Self
pub fn from_query(query: &Query) -> Self
Sourcepub fn from_query_ignore_case(query: &Query) -> Self
pub fn from_query_ignore_case(query: &Query) -> Self
Sourcepub fn from_query_str(query: &str) -> Result<Self, QueryParseError>
pub fn from_query_str(query: &str) -> Result<Self, QueryParseError>
Sourcepub fn from_query_str_ignore_case(query: &str) -> Result<Self, QueryParseError>
pub fn from_query_str_ignore_case(query: &str) -> Result<Self, QueryParseError>
Sourcepub fn is_accepting_state(&self, state: usize) -> bool
pub fn is_accepting_state(&self, state: usize) -> bool
Check if a given state is accepting/final.
Sourcepub fn get_field_symbol_id(&self, field: &str) -> usize
pub fn get_field_symbol_id(&self, field: &str) -> usize
Get the symbol index for a field name. When the DFA was built with case-insensitive matching, the key is lowercased before lookup.
Sourcepub fn get_index_symbol_id(&self, index: usize) -> Option<usize>
pub fn get_index_symbol_id(&self, index: usize) -> Option<usize>
Get the symbol index for an array index by performing a binary search over the sorted vector of all range entries.