[][src]Function kmp::kmp_find_with_lsp_table

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

Finds a needle in a haystack using the Knuth–Morris–Pratt algorithm with a given longest suffix-prefix table generated by kmp_table.

Returns None if the needle could not be found.

If you're only searching in a single haystack consider using kmp_find for convenience.

Examples

use kmp::{kmp_find_with_lsp_table, kmp_table};

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

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

assert_eq!(kmp_find_with_lsp_table(needle, &['a', 'a', 'b', 'a', 'c', 'd', 'a', 'd'], &table), Some(0));
assert_eq!(kmp_find_with_lsp_table(needle, &['d', 'c', 'a', 'b', 'a', 'a', 'b', 'a'], &table), Some(4));