cd6c97ea60
MozReview-Commit-ID: BOgu41N351y --HG-- rename : third_party/rust/serde/.cargo-checksum.json => third_party/rust/serde-0.8.23/.cargo-checksum.json rename : third_party/rust/serde/Cargo.toml => third_party/rust/serde-0.8.23/Cargo.toml rename : third_party/rust/serde/src/bytes.rs => third_party/rust/serde-0.8.23/src/bytes.rs rename : third_party/rust/serde/src/de/impls.rs => third_party/rust/serde-0.8.23/src/de/impls.rs rename : third_party/rust/serde/src/de/mod.rs => third_party/rust/serde-0.8.23/src/de/mod.rs rename : third_party/rust/serde/src/de/value.rs => third_party/rust/serde-0.8.23/src/de/value.rs rename : third_party/rust/serde/src/error.rs => third_party/rust/serde-0.8.23/src/error.rs rename : third_party/rust/serde/src/lib.rs => third_party/rust/serde-0.8.23/src/lib.rs rename : third_party/rust/serde/src/macros.rs => third_party/rust/serde-0.8.23/src/macros.rs rename : third_party/rust/serde/src/ser/impls.rs => third_party/rust/serde-0.8.23/src/ser/impls.rs rename : third_party/rust/serde/src/ser/mod.rs => third_party/rust/serde-0.8.23/src/ser/mod.rs extra : rebase_source : d015147c7a6c01b34c5a1abf035d71f8ecfe0c12 |
||
---|---|---|
.. | ||
benches | ||
examples | ||
src | ||
.cargo-checksum.json | ||
.cargo-ok | ||
.gitignore | ||
.travis.yml | ||
COPYING | ||
Cargo.toml | ||
LICENSE-MIT | ||
Makefile | ||
README.md | ||
UNLICENSE | ||
ctags.rust | ||
session.vim |
README.md
This crate provides an implementation of the Aho-Corasick algorithm. Its intended use case is for fast substring matching, particularly when matching multiple substrings in a search text. This is achieved by compiling the substrings into a finite state machine.
This implementation provides optimal algorithmic time complexity. Construction
of the finite state machine is O(p)
where p
is the length of the substrings
concatenated. Matching against search text is O(n + p + m)
, where n
is
the length of the search text and m
is the number of matches.
Dual-licensed under MIT or the UNLICENSE.
Documentation
http://burntsushi.net/rustdoc/aho_corasick/.
Example
The documentation contains several examples, and there is a more complete
example as a full program in examples/dict-search.rs
.
Here is a quick example showing simple substring matching:
use aho_corasick::{Automaton, AcAutomaton, Match};
let aut = AcAutomaton::new(vec!["apple", "maple"]);
let mut it = aut.find("I like maple apples.");
assert_eq!(it.next(), Some(Match {
pati: 1,
start: 7,
end: 12,
}));
assert_eq!(it.next(), Some(Match {
pati: 0,
start: 13,
end: 18,
}));
assert_eq!(it.next(), None);
Alternatives
Aho-Corasick is useful for matching multiple substrings against many long
strings. If your long string is fixed, then you might consider building a
suffix array
of the search text (which takes O(n)
time). Matches can then be found in
O(plogn)
time.