[][src]Function kmp::kmp_match_with_lsp_table

pub fn kmp_match_with_lsp_table<N, H>(
    needle: &[N],
    haystack: &[H],
    lsp: &[usize]
) -> Vec<usize> where
    N: PartialEq,
    H: PartialEq<N>, 

Matches a needle in a haystack using the Knuth–Morris–Pratt algorithm with a given longest suffix-prefix table generated by kmp_table and returns a vector of positions in the haystack.

For matches that overlap, only the indices corresponding to the first match are returned.

If you're only matching in a single haystack consider using kmp_match for convenience.

Examples

use kmp::{kmp_match_with_lsp_table, kmp_table};

let needle = &['a', 'b'];
let table = kmp_table(needle);

assert_eq!(table, vec![0, 0]);

assert_eq!(kmp_match_with_lsp_table(needle, &['a', 'a', 'b', 'a', 'c', 'd', 'a', 'b', 'd'], &table), vec![1, 6]);
assert_eq!(kmp_match_with_lsp_table(needle, &['d', 'c', 'a', 'b', 'a', 'a', 'b', 'a'], &table), vec![2, 5]);