Function triple_accel::hamming::hamming_search_naive[][src]

pub fn hamming_search_naive<'a>(
    needle: &'a [u8],
    haystack: &'a [u8]
) -> Box<dyn Iterator<Item = Match> + 'a>
Expand description

Returns an iterator over best Matchs by naively searching through the text haystack for the pattern needle.

This is done by naively counting mismatches at every position in haystack. Only the matches with the lowest Hamming distance are returned. Each returned Match requires at least half or more bytes of the needle to match somewhere in the haystack. The length of needle must be less than or equal to the length of haystack.

Arguments

  • needle - pattern string (slice)
  • haystack - text string (slice)

Example

let matches: Vec<Match> = hamming_search_naive(b"abc", b"  abd").collect();

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