#byte-string #string #find #memmem #pcmpestri #substring-search

unmaintained no-std twoway

(Deprecated - use crate memchr instead.) Fast substring search for strings and byte strings. Optional SSE4.2 acceleration (if detected at runtime) using pcmpestri. Memchr is the only mandatory dependency. The two way algorithm is also used by rust's libstd itself, but here it is exposed both for byte strings, using memchr, and optionally using a SSE4.2 accelerated version.

12 releases

Uses old Rust 2015

0.2.2 May 19, 2021
0.2.1 Oct 9, 2019
0.2.0 Nov 19, 2018
0.1.8 Mar 19, 2018
0.1.1 Dec 9, 2015

#5 in #memmem

Download history 62947/week @ 2024-07-22 66357/week @ 2024-07-29 63347/week @ 2024-08-05 60492/week @ 2024-08-12 52812/week @ 2024-08-19 51846/week @ 2024-08-26 51454/week @ 2024-09-02 48777/week @ 2024-09-09 45089/week @ 2024-09-16 47175/week @ 2024-09-23 52467/week @ 2024-09-30 46243/week @ 2024-10-07 50444/week @ 2024-10-14 50056/week @ 2024-10-21 46802/week @ 2024-10-28 44169/week @ 2024-11-04

194,698 downloads per month
Used in 310 crates (38 directly)

MIT/Apache

81KB
1.5K SLoC

This is my substring search workspace.

Please read the API documentation here

build_status

Documentation

Fast substring search for strings and byte strings, using the two-way algorithm.

This is the same code as is included in Rust's libstd to “power” str::find(&str), but here it is exposed with some improvements:

  • Available for byte string searches using &[u8]
  • Having an optional SSE4.2 accelerated version (if detected at runtime) which is even faster.
  • Using memchr for the single byte case, which is ultra fast.
  • twoway::find_bytes(text: &[u8], pattern: &[u8]) -> Option<usize>
  • twoway::rfind_bytes(text: &[u8], pattern: &[u8]) -> Option<usize>
  • twoway::find_str(text: &str, pattern: &str) -> Option<usize>
  • twoway::rfind_str(text: &str, pattern: &str) -> Option<usize>

Recent Changes

  • 0.2.1
    • Update dev-deps
  • 0.2.0
    • Use std::arch and transparently support SSE4.2 when possible (x86 and x86-64 only) to enable an accelerated implementation of the algorithm. Forward search only. By @RReverser and @bluss
    • Fix a bug in the SSE4.2 algorithm that made it much slower than it should have been, so performance increases as well.
    • Requires Rust 1.27
  • 0.1.8
    • Tweak crate keywords by @tari
    • Only testing and benchmarking changes otherwise (no changes to the crate itself)
  • 0.1.7
    • The crate is optionally no_std. Regular and pcmp both support this mode.
  • 0.1.6
    • The hidden and internal test module set, technically pub, was removed from standard compilation.
  • 0.1.5
    • Update from an odds dependency to using unchecked-index instead (only used by the pcmp feature).
    • The hidden and internal test module tw, technically pub, was removed from standard compilation.
  • 0.1.4
    • Update memchr dependency to 2.0
  • 0.1.3
    • Link to docs.rs docs
    • Drop pcmp's itertools dependency
    • Update nightly code for recent changes
  • 0.1.2
    • Internal improvements to the pcmp module.
  • 0.1.1
    • Add rfind_bytes, rfind_str
  • 0.1.0
    • Initial release
    • Add find_bytes, find_str

License

MIT / APACHE-2.0

Notes

Consider denying 0/n factorizations, see http://lists.gnu.org/archive/html/bug-gnulib/2010-06/msg00184.html

Dependencies

~125–290KB