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

pub fn levenshtein_search(needle: &[u8], haystack: &[u8]) -> Vec<Match>

Returns a vector of 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. Note that overlapping best matches may be returned. If multiple best matches end at the same position, then the longest match is chosen. Currently, this does not support null bytes/characters in the strings. 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 = levenshtein_search(b"abc", b"  abd");

// note: it is possible to end the match at two different positions
assert!(matches == vec![Match{start: 2, end: 4, k: 1}, Match{start: 2, end: 5, k: 1}]);