shift_and

Function shift_and 

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

An implementation of the Shift-And algorithm.

Takes a pattern, and text text.

If the given text contains the given pattern, the algorithm returns the indexes of the first letters of all found occurrences. If the pattern could not be found in the text, an empty vector is returned.

§Runtime

The worst case runtime is O(n * m), with n being the length of the text and m being the length of the pattern.

§When to Use It

The algorithm can be useful if you want to match short patterns.

§How It Works

The algorithm works by simulating a nondeterministic finite automaton (NFA) in memory using cheap bit operations.