use crate::general::automaton::Automaton;
pub trait DeterministicAutomaton: Automaton {
fn initial_state(&self) -> Self::State;
fn transition(&self, state: Self::State, input: &Self::Input) -> Option<Self::State>;
fn run_from(&self, state: Self::State, word: &[Self::Input]) -> Option<Self::State> {
let mut current_state = state;
for input in word {
current_state = self.transition(current_state, input)?;
}
Some(current_state)
}
fn accepts(&self, word: &[Self::Input]) -> bool {
let state = self.initial_state();
let Some(last_state) = self.run_from(state, word) else {
return false;
};
self.is_accepting_state(last_state)
}
}