[−][src]Function triple_accel::hamming::hamming_search_simd
pub fn hamming_search_simd<'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.
This is done by counting mismatches at every position in haystack
.
This will automatically fall back to hamming_search_naive_with_opts
if AVX2 and SSE4.1
are not supported.
Null bytes/characters are not supported.
The length of needle
must be less than or equal to the length of haystack
.
Each returned Match
requires at least half or more bytes of the needle
to match
somwhere in the haystack
.
Only the matches with the lowest Hamming distance are returned.
This should be faster than hamming_search_naive
.
Arguments
needle
- pattern string (slice)haystack
- text string (slice)
Panics
- When there are zero/null bytes in the
haystack
string.
Example
let matches: Vec<Match> = hamming_search_simd(b"abc", b" abd").collect(); assert!(matches == vec![Match{start: 2, end: 5, k: 1}]);