]> git.proxmox.com Git - cargo.git/blobdiff - vendor/aho-corasick/src/lib.rs
New upstream version 0.52.0
[cargo.git] / vendor / aho-corasick / src / lib.rs
index 0294d12e7409fb46c5ea6cdd044feacb63c15c62..9a3d084783b4fa0cc9954a1256db8d4fd693410c 100644 (file)
@@ -33,6 +33,10 @@ This section gives a brief overview of the primary types in this crate:
   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
@@ -164,18 +168,14 @@ naive solutions, it is generally slower than more specialized algorithms that
 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).
 */
 
@@ -186,23 +186,30 @@ performance in some cases. For that reason, prefilters can be disabled via
 #[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;
@@ -280,10 +287,11 @@ impl Match {
 
     #[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 }
     }
 }