Function triple_accel::levenshtein::levenshtein_search_naive [−][src]
pub fn levenshtein_search_naive<'a>(
needle: &'a [u8],
haystack: &'a [u8]
) -> Box<dyn Iterator<Item = Match> + 'a>
Expand description
Returns an iterator over the best Match
s by searching through the text haystack
for the
pattern needle
using the naive algorithm.
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
.
Arguments
needle
- pattern string (slice)haystack
- text string (slice)
Example
let matches: Vec<Match> = levenshtein_search_naive(b"abc", b" abd").collect(); assert!(matches == vec![Match{start: 2, end: 5, k: 1}]);