chimera: hybrid of Hyperscan and PCRE

This commit is contained in:
Wang, Xiang W
2018-03-09 03:52:12 -05:00
parent 8a1c497f44
commit bf87f8c003
47 changed files with 6985 additions and 202 deletions

View File

@@ -35,25 +35,36 @@
#include <utility>
#include <vector>
// Type for capturing groups: a vector of (from, to) offsets, with both set to
// -1 for inactive groups (like pcre's ovector). Used by hybrid modes.
typedef std::vector<std::pair<int, int> > CaptureVec;
// Class representing a single match, encapsulating to/from offsets.
class MatchResult {
public:
MatchResult(unsigned long long start, unsigned long long end)
: from(start), to(end) {}
MatchResult(unsigned long long start, unsigned long long end,
const CaptureVec &cap)
: from(start), to(end), captured(cap) {}
bool operator<(const MatchResult &a) const {
if (from != a.from) {
return from < a.from;
}
return to < a.to;
if (to != a.to) {
return to < a.to;
}
return captured < a.captured;
}
bool operator==(const MatchResult &a) const {
return from == a.from && to == a.to;
return from == a.from && to == a.to && captured == a.captured;
}
unsigned long long from;
unsigned long long to;
CaptureVec captured;
};
enum ResultSource {
@@ -114,6 +125,19 @@ public:
}
}
// Add a match (with capturing vector)
void addMatch(unsigned long long from, unsigned long long to,
const CaptureVec &cap, int block = 0) {
MatchResult m(from, to, cap);
matches.insert(m);
if (matches_by_block[block].find(m) != matches_by_block[block].end()) {
dupe_matches.insert(m);
} else {
matches_by_block[block].insert(m);
}
}
// Clear all matches.
void clear() {
matches.clear();