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, 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 haystack = b"Samwise";
let mut state = OverlappingState::start();

// First, 'Sam' will match.
let end1 = sparse_re.find_overlapping_fwd_at(
    None, None, haystack, 0, haystack.len(), &mut state,
)?;
assert_eq!(end1, Some(HalfMatch::must(0, 3)));

// And now 'Samwise' will match.
let end2 = sparse_re.find_overlapping_fwd_at(
    None, None, haystack, 3, haystack.len(), &mut state,
)?;
assert_eq!(end2, Some(HalfMatch::must(0, 7)));

Structs

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