Skip to main content

QueryDFA

Struct QueryDFA 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§num_states: usize

The number of states in the DFA

§start_state: usize

The 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: bool

Whether fields are case-sensitive.

Implementations§

Source§

impl QueryDFA

Source

pub fn from_query(query: &Query) -> Self

Constructs a new QueryDFA from a constructed Query.

Source

pub fn from_query_ignore_case(query: &Query) -> Self

Constructs a new case-insensitive QueryDFA from a constructed Query. Field names in the query and in JSON keys are compared after lowercasing.

Source

pub fn from_query_str(query: &str) -> Result<Self, QueryParseError>

Attempt to construct a new QueryDFA from the query string.

§Errors

Returns an error in the case of an invalid query string.

Source

pub fn from_query_str_ignore_case(query: &str) -> Result<Self, QueryParseError>

Attempt to construct a new case-insensitive QueryDFA from the query string.

§Errors

Returns an error in the case of an invalid query string.

Source

pub fn is_accepting_state(&self, state: usize) -> bool

Check if a given state is accepting/final.

Source

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.

Source

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.

Source

pub fn transition(&self, state: usize, symbol_id: usize) -> Option<usize>

Get the next state given current state and symbol.

Source

pub const fn index_in_range( &self, index: usize, start: usize, end: usize, ) -> bool

Check whether a given index satisfies a range bounds.

Trait Implementations§

Source§

impl Display for QueryDFA

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.