[−][src]Function triple_accel::levenshtein::levenshtein_search
pub fn levenshtein_search<'a>(
needle: &'a [u8],
haystack: &'a [u8]
) -> Box<dyn Iterator<Item = Match> + 'a>
Returns an iterator over best Match
s 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 Match
es 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}]);