Function algos::pattern::bruteforce [−][src]
pub fn bruteforce(pattern: &[u8], find: &[u8]) -> Result<usize, usize>
Brute Force: 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.
Case | Time complexity | Space complexity |
---|---|---|
Best: | Ω(m*(n-m+1)) | |
Avrg: | θ(m*(n-m+1)) | |
Worst: | O(m*(n-m+1)) | O(1) |
Example
use algos::pattern; let p = "ATCGGATTTCAGAAGCT".as_bytes(); let find = pattern::bruteforce(&p, &"TTT".as_bytes()); assert_eq!(find, Ok(6));