regex_automata::dfa

Module sparse

Source
Available on (crate features dfa-search or dfa-onepass) and crate feature dfa-search only.
Expand description

Types and routines specific to sparse DFAs.

This module is the home of sparse::DFA.

Unlike the dense module, this module does not contain a builder or configuration specific for sparse DFAs. Instead, the intended way to build a sparse DFA is either by using a default configuration with its constructor sparse::DFA::new, or by first configuring the construction of a dense DFA with dense::Builder and then calling dense::DFA::to_sparse. For example, this configures a sparse DFA to do an overlapping search:

use regex_automata::{
    dfa::{Automaton, OverlappingState, dense},
    HalfMatch, Input, MatchKind,
};

let dense_re = dense::Builder::new()
    .configure(dense::Config::new().match_kind(MatchKind::All))
    .build(r"Samwise|Sam")?;
let sparse_re = dense_re.to_sparse()?;

// Setup our haystack and initial start state.
let input = Input::new("Samwise");
let mut state = OverlappingState::start();

// First, 'Sam' will match.
sparse_re.try_search_overlapping_fwd(&input, &mut state)?;
assert_eq!(Some(HalfMatch::must(0, 3)), state.get_match());

// And now 'Samwise' will match.
sparse_re.try_search_overlapping_fwd(&input, &mut state)?;
assert_eq!(Some(HalfMatch::must(0, 7)), state.get_match());

Structsยง

  • A sparse deterministic finite automaton (DFA) with variable sized states.