mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
ng_find_matches: use wd.active for accepts too
This commit is contained in:
parent
bae8ebc62d
commit
834aebe8b6
@ -668,8 +668,8 @@ struct StateSet {
|
|||||||
sort_and_unique(result);
|
sort_and_unique(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_set<State> getAcceptStates(const GraphCache &gc) const {
|
void getAcceptStates(const GraphCache &gc, vector<State> &result) const {
|
||||||
flat_set<State> result;
|
result.clear();
|
||||||
|
|
||||||
for (u32 dist = 0; dist <= edit_distance; dist++) {
|
for (u32 dist = 0; dist <= edit_distance; dist++) {
|
||||||
// get all shadow vertices (including original graph)
|
// get all shadow vertices (including original graph)
|
||||||
@ -678,24 +678,24 @@ struct StateSet {
|
|||||||
for (size_t id = cur_shadow_vertices.find_first();
|
for (size_t id = cur_shadow_vertices.find_first();
|
||||||
id != cur_shadow_vertices.npos;
|
id != cur_shadow_vertices.npos;
|
||||||
id = cur_shadow_vertices.find_next(id)) {
|
id = cur_shadow_vertices.find_next(id)) {
|
||||||
result.emplace(id, dist, shadows_som[dist][id],
|
result.emplace_back(id, dist, shadows_som[dist][id],
|
||||||
State::NODE_SHADOW);
|
State::NODE_SHADOW);
|
||||||
}
|
}
|
||||||
auto cur_helper_vertices = helpers[dist];
|
auto cur_helper_vertices = helpers[dist];
|
||||||
cur_helper_vertices &= gc.getAcceptTransitions(dist);
|
cur_helper_vertices &= gc.getAcceptTransitions(dist);
|
||||||
for (size_t id = cur_helper_vertices.find_first();
|
for (size_t id = cur_helper_vertices.find_first();
|
||||||
id != cur_helper_vertices.npos;
|
id != cur_helper_vertices.npos;
|
||||||
id = cur_helper_vertices.find_next(id)) {
|
id = cur_helper_vertices.find_next(id)) {
|
||||||
result.emplace(id, dist, helpers_som[dist][id],
|
result.emplace_back(id, dist, helpers_som[dist][id],
|
||||||
State::NODE_HELPER);
|
State::NODE_HELPER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
sort_and_unique(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_set<State> getAcceptEodStates(const GraphCache &gc) const {
|
void getAcceptEodStates(const GraphCache &gc, vector<State> &result) const {
|
||||||
flat_set<State> result;
|
result.clear();
|
||||||
|
|
||||||
for (u32 dist = 0; dist <= edit_distance; dist++) {
|
for (u32 dist = 0; dist <= edit_distance; dist++) {
|
||||||
// get all shadow vertices (including original graph)
|
// get all shadow vertices (including original graph)
|
||||||
@ -704,20 +704,20 @@ struct StateSet {
|
|||||||
for (size_t id = cur_shadow_vertices.find_first();
|
for (size_t id = cur_shadow_vertices.find_first();
|
||||||
id != cur_shadow_vertices.npos;
|
id != cur_shadow_vertices.npos;
|
||||||
id = cur_shadow_vertices.find_next(id)) {
|
id = cur_shadow_vertices.find_next(id)) {
|
||||||
result.emplace(id, dist, shadows_som[dist][id],
|
result.emplace_back(id, dist, shadows_som[dist][id],
|
||||||
State::NODE_SHADOW);
|
State::NODE_SHADOW);
|
||||||
}
|
}
|
||||||
auto cur_helper_vertices = helpers[dist];
|
auto cur_helper_vertices = helpers[dist];
|
||||||
cur_helper_vertices &= gc.getAcceptEodTransitions(dist);
|
cur_helper_vertices &= gc.getAcceptEodTransitions(dist);
|
||||||
for (size_t id = cur_helper_vertices.find_first();
|
for (size_t id = cur_helper_vertices.find_first();
|
||||||
id != cur_helper_vertices.npos;
|
id != cur_helper_vertices.npos;
|
||||||
id = cur_helper_vertices.find_next(id)) {
|
id = cur_helper_vertices.find_next(id)) {
|
||||||
result.emplace(id, dist, helpers_som[dist][id],
|
result.emplace_back(id, dist, helpers_som[dist][id],
|
||||||
State::NODE_HELPER);
|
State::NODE_HELPER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
sort_and_unique(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the caller must specify SOM at current offset, and must not attempt to
|
// the caller must specify SOM at current offset, and must not attempt to
|
||||||
@ -864,12 +864,16 @@ bool canReach(const NGHolder &g, const NFAEdge &e, struct fmstate &state) {
|
|||||||
|
|
||||||
static
|
static
|
||||||
void getAcceptMatches(const NGHolder &g, MatchSet &matches,
|
void getAcceptMatches(const NGHolder &g, MatchSet &matches,
|
||||||
struct fmstate &state, NFAVertex accept_vertex) {
|
struct fmstate &state, NFAVertex accept_vertex,
|
||||||
|
vector<StateSet::State> &active_states) {
|
||||||
assert(accept_vertex == g.accept || accept_vertex == g.acceptEod);
|
assert(accept_vertex == g.accept || accept_vertex == g.acceptEod);
|
||||||
|
|
||||||
const bool eod = accept_vertex == g.acceptEod;
|
const bool eod = accept_vertex == g.acceptEod;
|
||||||
auto active_states = eod ? state.states.getAcceptEodStates(state.gc)
|
if (eod) {
|
||||||
: state.states.getAcceptStates(state.gc);
|
state.states.getAcceptEodStates(state.gc, active_states);
|
||||||
|
} else {
|
||||||
|
state.states.getAcceptStates(state.gc, active_states);
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG_PRINTF("Number of active states: %zu\n", active_states.size());
|
DEBUG_PRINTF("Number of active states: %zu\n", active_states.size());
|
||||||
|
|
||||||
@ -908,13 +912,12 @@ void getAcceptMatches(const NGHolder &g, MatchSet &matches,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
void getMatches(const NGHolder &g, MatchSet &matches, struct fmstate &state,
|
void getMatches(const NGHolder &g, MatchSet &matches, struct fmstate &state,
|
||||||
bool allowEodMatches) {
|
StateSet::WorkingData &wd, bool allowEodMatches) {
|
||||||
getAcceptMatches(g, matches, state, g.accept);
|
getAcceptMatches(g, matches, state, g.accept, wd.active);
|
||||||
if (allowEodMatches) {
|
if (allowEodMatches) {
|
||||||
getAcceptMatches(g, matches, state, g.acceptEod);
|
getAcceptMatches(g, matches, state, g.acceptEod, wd.active);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1083,7 +1086,7 @@ bool findMatches(const NGHolder &g, const ReportManager &rm,
|
|||||||
|
|
||||||
step(g, state, wd);
|
step(g, state, wd);
|
||||||
|
|
||||||
getMatches(g, matches, state, false);
|
getMatches(g, matches, state, wd, false);
|
||||||
|
|
||||||
DEBUG_PRINTF("offset %zu, %zu states on\n", state.offset,
|
DEBUG_PRINTF("offset %zu, %zu states on\n", state.offset,
|
||||||
state.next.count());
|
state.next.count());
|
||||||
@ -1104,7 +1107,7 @@ bool findMatches(const NGHolder &g, const ReportManager &rm,
|
|||||||
// matches also (or not, if we're in notEod mode)
|
// matches also (or not, if we're in notEod mode)
|
||||||
|
|
||||||
DEBUG_PRINTF("Looking for EOD matches\n");
|
DEBUG_PRINTF("Looking for EOD matches\n");
|
||||||
getMatches(g, matches, state, !notEod);
|
getMatches(g, matches, state, wd, !notEod);
|
||||||
|
|
||||||
filterMatches(matches);
|
filterMatches(matches);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user