Function triple_accel::levenshtein::levenshtein_search_simd[][src]

pub fn levenshtein_search_simd<'a>(
    needle: &'a [u8],
    haystack: &'a [u8]
) -> Box<dyn Iterator<Item = Match> + 'a>
Expand description

Returns an iterator over the best Matchs by searching through the text haystack for the pattern needle using SIMD acceleration.

The best matches are the matches with the lowest Levenshtein distance. If multiple best matches end at the same position or fully overlap, then the longest match is chosen. If needle is empty, then no Matches are returned. Each returned Match requires at least half or more bytes of the needle to match somewhere in the haystack. This should be much faster than levenshtein_search_naive. Internally, this will automatically use AVX or SSE vectors with 8-bit, 16-bit, or 32-bit elements to represent anti-diagonals in the dynamic programming matrix for calculating Levenshtein distance. If AVX2 or SSE4.1 is not supported, then this will automatically fall back to levenshtein_search_naive_with_opts.

Arguments

  • needle - pattern string (slice)
  • haystack - text string (slice)

Example

let matches: Vec<Match> = levenshtein_search_simd(b"abc", b"  abd").collect();

assert!(matches == vec![Match{start: 2, end: 5, k: 1}]);