[−][src]Struct generic_levenshtein::Levenshtein
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
impl RefUnwindSafe for Levenshtein
impl Send for Levenshtein
impl Sync for Levenshtein
impl Unpin for Levenshtein
impl UnwindSafe for Levenshtein
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,