# Function strsim::normalized_levenshtein

source · [−]

    pub fn normalized_levenshtein(a: &str, b: &str) -> f64

Expand description

Calculates a normalized score of the Levenshtein algorithm between 0.0 and 1.0 (inclusive), where 1.0 means the strings are the same.

    use strsim::normalized_levenshtein;

    assert!((normalized_levenshtein("kitten", "sitting") - 0.57142).abs() < 0.00001);
    assert!((normalized_levenshtein("", "") - 1.0).abs() < 0.00001);
    assert!(normalized_levenshtein("", "second").abs() < 0.00001);
    assert!(normalized_levenshtein("first", "").abs() < 0.00001);
    assert!((normalized_levenshtein("string", "string") - 1.0).abs() < 0.00001);