• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..01-Sep-2019-

benches/H03-May-2022-374311

ci/H01-Sep-2019-2110

examples/H01-Sep-2019-139125

src/H01-Sep-2019-1,7741,316

.cargo-checksum.jsonH A D01-Sep-20191.4 KiB11

.travis.ymlH A D01-Sep-2019116 1110

COPYINGH A D01-Sep-2019126 42

Cargo.tomlH A D01-Sep-20191.6 KiB7360

LICENSE-MITH A D01-Sep-20191.1 KiB2217

MakefileH A D01-Sep-2019253 1511

README.mdH A D01-Sep-20191.8 KiB5640

UNLICENSEH A D01-Sep-20191.2 KiB2520

ctags.rustH A D01-Sep-2019902 1211

session.vimH A D01-Sep-201956 21

README.md

1This crate provides an implementation of the
2[Aho-Corasick](http://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_string_matching_algorithm)
3algorithm. Its intended use case is for fast substring matching, particularly
4when matching multiple substrings in a search text. This is achieved by
5compiling the substrings into a finite state machine.
6
7This implementation provides optimal algorithmic time complexity. Construction
8of the finite state machine is `O(p)` where `p` is the length of the substrings
9concatenated. Matching against search text is `O(n + p + m)`, where `n` is
10the length of the search text and `m` is the number of matches.
11
12[![Build status](https://api.travis-ci.org/BurntSushi/aho-corasick.png)](https://travis-ci.org/BurntSushi/aho-corasick)
13[![](http://meritbadge.herokuapp.com/aho-corasick)](https://crates.io/crates/aho-corasick)
14
15Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
16
17
18### Documentation
19
20[https://docs.rs/aho-corasick/](https://docs.rs/aho-corasick/).
21
22
23### Example
24
25The documentation contains several examples, and there is a more complete
26example as a full program in `examples/dict-search.rs`.
27
28Here is a quick example showing simple substring matching:
29
30```rust
31use aho_corasick::{Automaton, AcAutomaton, Match};
32
33let aut = AcAutomaton::new(vec!["apple", "maple"]);
34let mut it = aut.find("I like maple apples.");
35assert_eq!(it.next(), Some(Match {
36    pati: 1,
37    start: 7,
38    end: 12,
39}));
40assert_eq!(it.next(), Some(Match {
41    pati: 0,
42    start: 13,
43    end: 18,
44}));
45assert_eq!(it.next(), None);
46```
47
48
49### Alternatives
50
51Aho-Corasick is useful for matching multiple substrings against many long
52strings. If your long string is fixed, then you might consider building a
53[suffix array](https://github.com/BurntSushi/suffix)
54of the search text (which takes `O(n)` time). Matches can then be found in
55`O(plogn)` time.
56