Function triple_accel::levenshtein::levenshtein_search_naive_with_opts[][src]

pub fn levenshtein_search_naive_with_opts<'a>(
    needle: &'a [u8],
    haystack: &'a [u8],
    k: u32,
    search_type: SearchType,
    costs: EditCosts,
    anchored: bool
) -> Box<dyn Iterator<Item = Match> + 'a>
Expand description

Returns an iterator over Matchs by searching through the text haystack for the pattern needle using the naive algorithm, with extra options.

Note that overlapping matches may be returned. If multiple matches end at the same position, then the longest match is chosen. If needle is empty and anchored is false, then no Matches are returned.

Arguments

  • needle - pattern string (slice)
  • haystack - text string (slice)
  • k - maximum cost threshold for a match to be returned
  • search_type - indicates whether to return all matches (within a cost of k), or the best matches with the lowest cost (additionally, only the longest matches are retained for matches that fully overlap)
  • costs - EditCosts struct for the cost of each edit operation
  • anchored - whether the needle should be anchored to the start of the haystack string, causing any shifts to cost gap edits

Example

let matches: Vec<Match> = levenshtein_search_naive_with_opts(b"abc", b"  acb", 1, SearchType::All, RDAMERAU_COSTS, false).collect();

// note: it is possible to end the match at two different positions
assert!(matches == vec![Match{start: 2, end: 4, k: 1}, Match{start: 2, end: 5, k: 1}]);