that matched and the start and end byte offsets corresponding to the position
in the haystack at which it matched.
+Additionally, the [`packed`](packed/index.html) sub-module contains a lower
+level API for using fast vectorized routines for finding a small number of
+patterns in a haystack.
+
# Example: basic searching
This example shows how to search for occurrences of multiple patterns
are accelerated using vector instructions such as SIMD.
For that reason, this library will internally use a "prefilter" to attempt
-to accelerate searches when possible. Currently, this library has fairly
-limited implementation that only applies when there are 3 or fewer unique
-starting bytes among all patterns in an automaton.
-
-In the future, it is intended for this prefilter to grow more sophisticated
-by pushing applicable optimizations from the
-[`regex`](http://docs.rs/regex)
-crate (and other places) down into this library.
-
-While a prefilter is generally good to have on by default since it works well
-in the common case, it can lead to less predictable or even sub-optimal
-performance in some cases. For that reason, prefilters can be disabled via
+to accelerate searches when possible. Currently, this library has several
+different algorithms it might use depending on the patterns provided. Once the
+number of patterns gets too big, prefilters are no longer used.
+
+While a prefilter is generally good to have on by default since it works
+well in the common case, it can lead to less predictable or even sub-optimal
+performance in some cases. For that reason, prefilters can be explicitly
+disabled via
[`AhoCorasickBuilder::prefilter`](struct.AhoCorasickBuilder.html#method.prefilter).
*/
#[cfg(not(feature = "std"))]
compile_error!("`std` feature is currently required to build this crate");
-extern crate memchr;
+// #[cfg(doctest)]
+// #[macro_use]
+// extern crate doc_comment;
+
+// #[cfg(doctest)]
+// doctest!("../README.md");
-pub use ahocorasick::{
- AhoCorasick, AhoCorasickBuilder, MatchKind,
- FindIter, FindOverlappingIter, StreamFindIter,
+pub use crate::ahocorasick::{
+ AhoCorasick, AhoCorasickBuilder, FindIter, FindOverlappingIter, MatchKind,
+ StreamFindIter,
};
-pub use error::{Error, ErrorKind};
-pub use state_id::StateID;
+pub use crate::error::{Error, ErrorKind};
+pub use crate::state_id::StateID;
mod ahocorasick;
mod automaton;
mod buffer;
+mod byte_frequencies;
+mod classes;
mod dfa;
mod error;
-mod classes;
-mod prefilter;
mod nfa;
+pub mod packed;
+mod prefilter;
mod state_id;
#[cfg(test)]
mod tests;
#[inline]
fn increment(&self, by: usize) -> Match {
- Match {
- pattern: self.pattern,
- len: self.len,
- end: self.end + by,
- }
+ Match { pattern: self.pattern, len: self.len, end: self.end + by }
+ }
+
+ #[inline]
+ fn from_span(id: usize, start: usize, end: usize) -> Match {
+ Match { pattern: id, len: end - start, end }
}
}