Function triple_accel::levenshtein::levenshtein_search[][src]

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

Returns an iterator over 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. Internally, this will call levenshtein_search_simd. If AVX2 or SSE4.1 is not supported, then this will automatically fall back to a scalar alternative.

Arguments

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

Example

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

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