getMatches: simplify

This commit is contained in:
Justin Viiret 2017-03-08 16:27:41 +11:00 committed by Matthew Barr
parent c81c30b144
commit 749e3e64b9

View File

@ -868,18 +868,13 @@ bool canReach(const NGHolder &g, const NFAEdge &e, struct fmstate &state) {
} }
static static
void getMatches(const NGHolder &g, MatchSet &matches, struct fmstate &state, void getAcceptMatches(const NGHolder &g, MatchSet &matches,
bool allowEodMatches) { struct fmstate &state, NFAVertex accept_vertex) {
flat_set<NFAVertex> accepts {g.accept, g.acceptEod}; assert(accept_vertex == g.accept || accept_vertex == g.acceptEod);
for (auto v : accepts) { const bool eod = accept_vertex == g.acceptEod;
bool eod = v == g.acceptEod; auto active_states = eod ? state.states.getAcceptEodStates(state.gc)
if (eod && !allowEodMatches) { : state.states.getAcceptStates(state.gc);
continue;
}
auto active_states = eod ? state.states.getAcceptEodStates(state.gc) :
state.states.getAcceptStates(state.gc);
DEBUG_PRINTF("Number of active states: %zu\n", active_states.size()); DEBUG_PRINTF("Number of active states: %zu\n", active_states.size());
@ -892,32 +887,39 @@ void getMatches(const NGHolder &g, MatchSet &matches, struct fmstate &state,
} }
const auto &reports = const auto &reports =
eod ? eod ? state.gc.vertex_eod_reports_by_level[cur.level][u]
state.gc.vertex_eod_reports_by_level[cur.level][u] : : state.gc.vertex_reports_by_level[cur.level][u];
state.gc.vertex_reports_by_level[cur.level][u];
NFAEdge e = edge(u, v, g); NFAEdge e = edge(u, accept_vertex, g);
// we assume edge assertions only exist at level 0 // we assume edge assertions only exist at level 0
if (e && !canReach(g, e, state)) { if (e && !canReach(g, e, state)) {
continue; continue;
} }
DEBUG_PRINTF("%smatch found at %zu\n", DEBUG_PRINTF("%smatch found at %zu\n", eod ? "eod " : "", state.offset);
eod ? "eod " : "", state.offset);
assert(!reports.empty()); assert(!reports.empty());
for (const auto &report_id : reports) { for (const auto &report_id : reports) {
const Report &ri = state.rm.getReport(report_id); const Report &ri = state.rm.getReport(report_id);
DEBUG_PRINTF("report %u has offset adjustment %d\n", DEBUG_PRINTF("report %u has offset adjustment %d\n", report_id,
report_id, ri.offsetAdjust); ri.offsetAdjust);
DEBUG_PRINTF("match from (i:%zu,l:%u,t:%u): (%zu,%zu)\n", DEBUG_PRINTF("match from (i:%zu,l:%u,t:%u): (%zu,%zu)\n", cur.idx,
cur.idx, cur.level, cur.type, cur.som, cur.level, cur.type, cur.som,
state.offset + ri.offsetAdjust); state.offset + ri.offsetAdjust);
matches.emplace(cur.som, state.offset + ri.offsetAdjust); matches.emplace(cur.som, state.offset + ri.offsetAdjust);
} }
} }
}
static
void getMatches(const NGHolder &g, MatchSet &matches, struct fmstate &state,
bool allowEodMatches) {
getAcceptMatches(g, matches, state, g.accept);
if (allowEodMatches) {
getAcceptMatches(g, matches, state, g.acceptEod);
} }
} }