Skip to main content

z_search

Function z_search 

Source
pub fn z_search(pattern: &[u8], text: &[u8]) -> SeqResult<Vec<usize>>
Expand description

Find every occurrence of pattern in text using the Z-algorithm on the pattern ++ sep ++ text construction, returning start offsets in ascending order.

Each returned index j satisfies text[j..j + pattern.len()] == pattern. Overlapping occurrences are all reported (e.g. searching "aa" in "aaaa" yields [0, 1, 2]).

§Errors

Returns SeqError::EmptyInput if pattern is empty: an empty pattern has no well-defined occurrence set here (it would “match” at every position), matching the convention used by the Aho–Corasick automaton in this crate.

§Examples

use oxicuda_seq::string::z_search;

assert_eq!(z_search(b"ab", b"abcabxabc").expect("ok"), vec![0, 3, 6]);
assert_eq!(z_search(b"aa", b"aaaa").expect("ok"), vec![0, 1, 2]);
assert!(z_search(b"z", b"abc").expect("ok").is_empty());