Struct levenshtein_automata::DFA [−][src]
pub struct DFA { /* fields omitted */ }
Expand description
Implementation of a Deterministic Finite Automaton for a Levenshtein Automaton targeting UTF-8 encoded strings.
The automaton does not validate utf-8
.
It will not return errors when fed with invalid utf-8
The only sink
state is guaranteed to be SINK
.
This means that if you reach the sink state you are guaranteed that regardless of the sequence of bytes you might consume in the future, you will always remain in the same state.
This property can be exploited to abort further evaluation.
Usage
let mut state = dfa.initial_state(); for &byte in str.as_bytes() { state = dfa.transition(state, byte); if state == SINK_STATE { break; } } let distance = dfa.distance(state);
Implementations
impl DFA
[src]
impl DFA
[src]pub fn initial_state(&self) -> u32
[src]
pub fn initial_state(&self) -> u32
[src]Returns the initial state
pub fn eval<B: AsRef<[u8]>>(&self, text: B) -> Distance
[src]
pub fn eval<B: AsRef<[u8]>>(&self, text: B) -> Distance
[src]Helper function that consumes all of the bytes a sequence of bytes and returns the resulting distance.
pub fn distance(&self, state_id: u32) -> Distance
[src]
pub fn distance(&self, state_id: u32) -> Distance
[src]Returns the Levenshtein distance associated to the current state.
pub fn num_states(&self) -> usize
[src]
pub fn num_states(&self) -> usize
[src]Returns the number of states in the DFA
.
pub fn transition(&self, from_state_id: u32, b: u8) -> u32
[src]
pub fn transition(&self, from_state_id: u32, b: u8) -> u32
[src]Returns the destination state reached after consuming a given byte.