mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
limex: tidy up scoring code
This commit is contained in:
parent
8648397257
commit
e915ca21c5
@ -2172,20 +2172,18 @@ aligned_unique_ptr<NFA> generate(NGHolder &h,
|
|||||||
// Acceleration analysis.
|
// Acceleration analysis.
|
||||||
fillAccelInfo(arg);
|
fillAccelInfo(arg);
|
||||||
|
|
||||||
typedef pair<int, NFAEngineType> EngineScore;
|
vector<pair<int, NFAEngineType>> scores;
|
||||||
vector<EngineScore> scores;
|
|
||||||
|
|
||||||
if (hint != INVALID_NFA) {
|
if (hint != INVALID_NFA) {
|
||||||
// The caller has told us what to (attempt to) build.
|
// The caller has told us what to (attempt to) build.
|
||||||
scores.push_back(make_pair(0, (NFAEngineType)hint));
|
scores.emplace_back(0, (NFAEngineType)hint);
|
||||||
} else {
|
} else {
|
||||||
for (size_t i = 0; i <= LAST_LIMEX_NFA; i++) {
|
for (size_t i = 0; i <= LAST_LIMEX_NFA; i++) {
|
||||||
NFAEngineType ntype = (NFAEngineType)i;
|
NFAEngineType ntype = (NFAEngineType)i;
|
||||||
|
|
||||||
int score = DISPATCH_BY_LIMEX_TYPE(ntype, scoreNfa, arg);
|
int score = DISPATCH_BY_LIMEX_TYPE(ntype, scoreNfa, arg);
|
||||||
DEBUG_PRINTF("%s scores %d\n", nfa_type_name(ntype), score);
|
|
||||||
if (score >= 0) {
|
if (score >= 0) {
|
||||||
scores.push_back(make_pair(score, ntype));
|
DEBUG_PRINTF("%s scores %d\n", nfa_type_name(ntype), score);
|
||||||
|
scores.emplace_back(score, ntype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2195,22 +2193,22 @@ aligned_unique_ptr<NFA> generate(NGHolder &h,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
sort(scores.begin(), scores.end(), less<EngineScore>());
|
// Sort acceptable models in priority order, lowest score first.
|
||||||
|
sort(scores.begin(), scores.end());
|
||||||
|
|
||||||
aligned_unique_ptr<NFA> nfa;
|
for (const auto &elem : scores) {
|
||||||
for (auto i = scores.begin(); !nfa && i != scores.end(); ++i) {
|
assert(elem.first >= 0);
|
||||||
assert(i->first >= 0);
|
NFAEngineType limex_model = elem.second;
|
||||||
nfa = DISPATCH_BY_LIMEX_TYPE(i->second, generateNfa, arg);
|
auto nfa = DISPATCH_BY_LIMEX_TYPE(limex_model, generateNfa, arg);
|
||||||
|
if (nfa) {
|
||||||
|
DEBUG_PRINTF("successful build with NFA engine: %s\n",
|
||||||
|
nfa_type_name(limex_model));
|
||||||
|
return nfa;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nfa) {
|
|
||||||
DEBUG_PRINTF("NFA build failed.\n");
|
DEBUG_PRINTF("NFA build failed.\n");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG_PRINTF("successful build with NFA engine: %s\n",
|
|
||||||
nfa_type_name((NFAEngineType)nfa->type));
|
|
||||||
return nfa;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 countAccelStates(NGHolder &h,
|
u32 countAccelStates(NGHolder &h,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user