Function triple_accel::hamming::hamming_search[][src]

pub fn hamming_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.

This will automatically fall back to a scalar alternative 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 somewhere in the haystack. Only the matches with the lowest Hamming distance are returned. Internally, this calls hamming_search_simd.

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(b"abc", b"  abd").collect();

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