#string-search #string #search-pattern #search #pattern #substring #linear-time

no-std galil-seiferas

General string search in constant space, linear time, for nonorderable alphabets

6 releases

Uses old Rust 2015

0.1.5 Nov 25, 2017
0.1.4 Nov 21, 2017

#12 in #linear-time

Download history 547/week @ 2024-04-08 1997/week @ 2024-04-15 2208/week @ 2024-04-22 1326/week @ 2024-04-29 1154/week @ 2024-05-06 1592/week @ 2024-05-13 1187/week @ 2024-05-20 1524/week @ 2024-05-27 1568/week @ 2024-06-03 1420/week @ 2024-06-10 1016/week @ 2024-06-17 1765/week @ 2024-06-24 2075/week @ 2024-07-01 1405/week @ 2024-07-08 1292/week @ 2024-07-15 1769/week @ 2024-07-22

6,800 downloads per month
Used in 3 crates

MIT/Apache

38KB
714 lines

General string search in constant space, linear time, for nonorderable alphabets. Also known as exact string matching.

In Rust terms this means we can define the function:

fn gs_find<T: Eq>(text: &[T], pattern: &[T]) -> Option<usize> {
    // ...
}

and the function computes in O(n) time and O(1) space. In the worst case, this algorithm makes 4 n character comparisons.

Note that the Crochemore-Perrin (“Two Way” algorithm) is much superior if there is a linear order for the alphabet.

This work is Copyright 2017 by Ulrik Sverdrup "bluss"; see license terms in the package.

References

Both papers are recommended reading. The comments in this crate’s implementation are also meant to explain and point out important details, so that’s recommended reading too.

  • [GS] Z. Galil and J. Seiferas, Time-Space-Optimal String Matching, Journal of Computer and System Sciences (1983)
  • [CR] M. Crochemore and W. Rytter, Squares, Cubes, and Time-Space Efficient String Searching, Algorithmica (1995)

Dependencies

~23KB