Algorithm-AhoCorasick-XS
view release on metacpan or search on metacpan
Matcher.hpp view on Meta::CPAN
struct match {
string keyword;
size_t start;
size_t end;
};
class Matcher {
vector<string> words;
Trie *root;
public:
Matcher(const vector<string> & keywords);
~Matcher();
vector <string> matches(const string& input) const;
vector <string> first_match(const string& input) const;
vector <match> match_details(const string &input) const;
private:
#ifndef __AHOCORASICK_TRIE_INCLUDED__
#define __AHOCORASICK_TRIE_INCLUDED__
#include <forward_list>
#include <string>
namespace AhoCorasick {
class Trie {
public:
unsigned char label = '\0';
// Empirically, an array of 8 delivers a good compromise between
// speed and memory usage.
Trie *children[8] = {nullptr};
Trie *next = nullptr;
// Extensions for AC automaton
Trie *fail = nullptr;
std::forward_list<int> out;
( run in 0.324 second using v1.01-cache-2.11-cpan-64827b87656 )