1 #ifndef AHO_ALGORITHM_H
\r
2 #define AHO_ALGORITHM_H
\r
12 At each step, the current node is extended by finding its daughter,
\r
13 and if that doesn't exist, finding its suffix's daughter,
\r
14 and if that doesn't work, finding its suffix's suffix's daughter,
\r
15 finally ending in the root node if nothing's seen before.
\r
30 class aho::trie * trie;
\r
32 std::vector<tstring> patterns;
\r
36 std::vector<class aho::trie *> list;
\r
38 void add_patterns_to_trie();
\r
41 * Sets which nodes in trie, are the searched patterns.
\r
43 void set_patterns_in_trie();
\r
48 void set_nodes_list();
\r
51 * Sets suffix links for each pattern in trie.
\r
53 void set_suffix_link();
\r
56 * Checks if node is a searched pattern.
\r
58 virtual bool is_pattern(class aho::trie * node) {
\r
59 return node->is_pattern();
\r
62 bool is_on_nodes_list(class aho::trie * node);
\r
65 * Gets node by its value
\r
67 class aho::trie * get_node(tstring value) {
\r
68 return this->trie->get_child(value, true);
\r
72 * Saves search results
\r
74 virtual void save_result(tstring search, uint position) {
\r
75 printf("%s: %d\n", search.c_str(), position);
\r
79 * Algorithm constructor. Initializes variables.
\r
81 algorithm() : trie(new aho::trie(TXT(""))) {
\r
85 * Algorithm destructor.
\r
88 if(this->trie != NULL) {
\r
92 void add_search_pattern(tstring pattern);
\r
95 * Sets subject text in which patterns will be searched.
\r
97 void set_search_subject(tstring subject) {
\r
98 this->subject = subject;
\r
101 void generate_trie();
\r