Open cheparukhin opened 10 years ago
Please show me your code.
Segmentation faults and exceptions occur when Char type is not char (e.g. int). When I change it to char, everything seems to work normally.
Also you forgot to include
Here's the simplified example that I made to demonstrate the errors:
#include <cstdlib>
#include <vector>
#include <limits>
#include <sstream>
#include <balgo/mpm/aho_corasick.h>
using Char = int;
std::vector<Char> MakeRandomSequence(int max_size) {
const int size = std::rand() % max_size + 1;
std::vector<Char> random_sequence;
random_sequence.reserve(size);
for (int i = 0; i < size; ++i) {
random_sequence.push_back(rand() % std::numeric_limits<Char>::max());
}
return random_sequence;
}
int main() {
std::vector<std::vector<Char>> dict;
for (int i = 0; i < 100; ++i) {
dict.push_back(MakeRandomSequence(50));
}
balgo::AhoCorasick<Char, size_t> ahocor;
for (const std::vector<Char>& entry: dict) {
ahocor.Insert(entry.data(), entry.size());
}
ahocor.Build();
const std::vector<Char> query = MakeRandomSequence(1000);
std::vector<size_t> matches;
ahocor.Match(query.data(), query.size(), &matches);
}
Segmentation fault occurs at line 361 in ac_da_trie.h when executing AhoCorasick::Build function.