pub fn find_all(
text: impl AsRef<[u8]>,
pattern: impl AsRef<[u8]>,
) -> Result<Vec<usize>>
Expand description
Finds all occurrences of a pattern in the given text using the Z-algorithm.
§Arguments
text
- The text to search inpattern
- The pattern to search for
§Returns
Result<Vec<usize>>
- A vector containing all starting positions where the pattern occurs in the text
§Errors
Error::EmptyPattern
if the pattern is emptyError::PatternTooLong
if pattern length exceeds text length
§Example
use algos::cs::string::z_algorithm;
let text = "AABAACAADAABAAABAA";
let pattern = "AABA";
let positions = z_algorithm::find_all(text, pattern).unwrap();
assert_eq!(positions, vec![0, 9, 13]);