logo
pub fn bounded_levenshtein(
    alpha: TextSlice<'_>,
    beta: TextSlice<'_>,
    k: u32
) -> Option<u32>
Expand description

SIMD-accelerated bounded Levenshtein (or Edit) distance between two strings. Complexity: O(k / w * (n + m)), with n and m being the length of the given texts, k being the threshold on the number of edits, and w being the length of the SIMD vectors (usually w = 16 or w = 32).

If the Levenshtein distance between two strings is greater than the threshold k, then None is returned. This is useful for efficiently calculating whether two strings are similar.

Example

use bio::alignment::distance::simd::*;

let x = b"ACCGTGGAT";
let y = b"AAAAACCGTTGAT";
// ----ACCGTGGAT
//     ||||| |||
// AAAAACCGTTGAT
let ldist = bounded_levenshtein(x, y, 5); // Distance is 5
assert_eq!(ldist, Some(5));

let ldist = bounded_levenshtein(x, y, 4); // Threshold too low!
assert_eq!(ldist, None);