[][src]Struct generic_levenshtein::Levenshtein

pub struct Levenshtein { /* fields omitted */ }

Holds custom weights for substitutions and insertion/deletion

Examples

  • One substitution is equivalent to an insertion and a deletion:
let lev = Levenshtein::new (1, 2);
// Substitute 'x' for 'b' -> cost = 2
assert_eq!(lev.distance ("abc", "axc"), 2);
// Insert 'x' and delete 'c' -> cost = 1+1 = 2
assert_eq!(lev.distance ("abc", "xab"), 2);
  • Have substitutions cost slightly more than insertions and deletions (but still less than a deletion followed by an insertion):
let lev = Levenshtein::new (2, 3);
// Substitute 'x' for 'b' -> cost = 3
assert_eq!(lev.distance ("abc", "axc"), 3);
// Insert 'x' and delete 'c' -> cost = 2+2 = 4
assert_eq!(lev.distance ("abc", "xab"), 4);

Methods

impl Levenshtein[src]

pub fn new(addrm_weight: usize, subst_weight: usize) -> Self[src]

Create a Levenshtein instance holding custom weights.

Arguments

  • addrm_weight Weight to use for insertions and deletions.
  • subst_weight Weight to use for substitutions.

pub fn distance<T: PartialEq, U: AsRef<[T]>>(&self, a: U, b: U) -> usize[src]

Compute the Levenshtein distance between two sequences using the stored custom weights.

Trait Implementations

impl Default for Levenshtein[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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.

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.