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]

pub fn initial_state(&self) -> u32[src]

Returns the initial state

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]

Returns the Levenshtein distance associated to the current state.

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]

Returns the destination state reached after consuming a given byte.

Auto Trait Implementations

impl RefUnwindSafe for DFA

impl Send for DFA

impl Sync for DFA

impl Unpin for DFA

impl UnwindSafe for DFA

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.