use std::collections::HashSet;
use std::hash::Hash;
use crate::arbitrary::Automaton;
use crate::arbitrary::DeterministicAutomaton;
use crate::finite::DeterministicFiniteAutomaton;
use crate::finite::FiniteAutomaton;
use crate::labeled::simple::SimpleLabeledDFA;
use super::SimpleBuildError;
use super::state::SimpleDFAState;
pub type SimpleDFA = SimpleLabeledDFA<()>;
impl SimpleDFA {
pub fn new_unchecked(
state_count: usize,
initial: SimpleDFAState,
accepting: impl IntoIterator<Item = SimpleDFAState>,
alphabet: impl IntoIterator<Item = char>,
transitions: impl IntoIterator<Item = (SimpleDFAState, char, SimpleDFAState)>,
) -> Self {
let labels = accepting.into_iter().map(|s| (s, ()));
SimpleLabeledDFA::new_labeled_unchecked(state_count, initial, labels, alphabet, transitions)
}
pub fn try_new(
state_count: usize,
initial: SimpleDFAState,
accepting: impl IntoIterator<Item = SimpleDFAState>,
alphabet: impl IntoIterator<Item = char>,
transitions: impl IntoIterator<Item = (SimpleDFAState, char, SimpleDFAState)>,
) -> Result<Self, SimpleBuildError> {
let labels = accepting.into_iter().map(|s| (s, ()));
SimpleLabeledDFA::try_new_labeled(state_count, initial, labels, alphabet, transitions)
}
pub fn label_all_accepting_states_with<Label: Hash + Eq + Clone>(
&self,
label: Label,
) -> SimpleLabeledDFA<Label> {
self.map_labels(|_| label.clone())
}
}
impl Automaton for SimpleDFA {
fn is_accepting_state(&self, state: Self::State) -> bool {
self.labels.contains_key(&state)
}
}
impl FiniteAutomaton for SimpleDFA {
fn accepting_states_set(&self) -> HashSet<Self::State> {
self.labels.keys().copied().collect()
}
}
impl DeterministicAutomaton for SimpleDFA {}
impl DeterministicFiniteAutomaton for SimpleDFA {}