Function algos::pattern::horspool [−][src]
pub fn horspool(pattern: &[u8], find: &[u8]) -> Result<usize, usize>
Horspool: Search for the pattern in the find
parameter in a slice.
It returns Ok
holding the index of the first character of find
that was found
or Err
holding the last index it searched if not find.
It is a variation of the Boyer-Moore algorithm.
Case | Time complexity | Space complexity |
---|---|---|
Best: | Ω(n/m) | |
Avrg: | θ(n+m) | |
Worst: | O(nm) | O(δ) |
Obs.: δ is the max size of u8.
Example
use algos::pattern; let p = "ATCGGATTTCAGAAGCT".as_bytes(); let find = pattern::horspool(&p, &"TTT".as_bytes()); assert_eq!(find, Ok(6));