A streaming Aho-Corasick automata for matching strings. This module is a low level interface, but can be used to construct more complex algorithms.
var createTrie =var createAC =var trie =//First build the trie data structuretrietrietrietrietrie//Next construct the automata and use it tovar automata =//Now run it on some datavar data = 123456789forvar state=automata i=0; i<datalength;//Process next symbolstate=state//Print out all matches at position iifstatevalue !== undefinedconsoleforvar cur = state; curvalue !== undefined; cur = curnextconsole
Here is some example output from the above program:
matches at position 2 :4matches at position 3 :15matches at position 4 :2matches at position 8 :3
npm install aho-corasick-automata
var createAC =
Creates an Aho-Corasick automata from the trie encoded as an array-trie
Returns A new Aho-Corasick automata
Returns the next state of the automata after processing
symbolis the next character in the stream to process
Returns The next state of the automata
A value representing the terminal of the automata.
undefined if there is no trie entry at this point
A pointer to the next entry in the linked list of values at this automata state. If the
value is undefined, then this is the last node in this list.
(c) 2013 Mikola Lysenko. MIT License