mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
ng_calc_components: add Grey box control
This commit is contained in:
committed by
Matthew Barr
parent
ba867ebaff
commit
560e522457
@@ -42,6 +42,7 @@ namespace ue2 {
|
||||
|
||||
Grey::Grey(void) :
|
||||
optimiseComponentTree(true),
|
||||
calcComponents(true),
|
||||
performGraphSimplification(true),
|
||||
prefilterReductions(true),
|
||||
removeEdgeRedundancy(true),
|
||||
@@ -209,6 +210,7 @@ void applyGreyOverrides(Grey *g, const string &s) {
|
||||
} while (0)
|
||||
|
||||
G_UPDATE(optimiseComponentTree);
|
||||
G_UPDATE(calcComponents);
|
||||
G_UPDATE(performGraphSimplification);
|
||||
G_UPDATE(prefilterReductions);
|
||||
G_UPDATE(removeEdgeRedundancy);
|
||||
|
@@ -41,6 +41,7 @@ struct Grey {
|
||||
|
||||
bool optimiseComponentTree;
|
||||
|
||||
bool calcComponents;
|
||||
bool performGraphSimplification;
|
||||
bool prefilterReductions;
|
||||
bool removeEdgeRedundancy;
|
||||
|
@@ -437,7 +437,7 @@ bool NG::addGraph(ExpressionInfo &expr, unique_ptr<NGHolder> g_ptr) {
|
||||
// Split the graph into a set of connected components and process those.
|
||||
// Note: this invalidates g_ptr.
|
||||
|
||||
auto g_comp = calcComponents(std::move(g_ptr));
|
||||
auto g_comp = calcComponents(std::move(g_ptr), cc.grey);
|
||||
assert(!g_comp.empty());
|
||||
|
||||
if (!som) {
|
||||
@@ -446,7 +446,7 @@ bool NG::addGraph(ExpressionInfo &expr, unique_ptr<NGHolder> g_ptr) {
|
||||
reformLeadingDots(*gc);
|
||||
}
|
||||
|
||||
recalcComponents(g_comp);
|
||||
recalcComponents(g_comp, cc.grey);
|
||||
}
|
||||
|
||||
if (processComponents(*this, expr, g_comp, som)) {
|
||||
|
@@ -55,6 +55,7 @@
|
||||
#include "ng_prune.h"
|
||||
#include "ng_undirected.h"
|
||||
#include "ng_util.h"
|
||||
#include "grey.h"
|
||||
#include "ue2common.h"
|
||||
#include "util/graph_range.h"
|
||||
#include "util/make_unique.h"
|
||||
@@ -376,12 +377,13 @@ void splitIntoComponents(unique_ptr<NGHolder> g,
|
||||
}));
|
||||
}
|
||||
|
||||
deque<unique_ptr<NGHolder>> calcComponents(unique_ptr<NGHolder> g) {
|
||||
deque<unique_ptr<NGHolder>> calcComponents(unique_ptr<NGHolder> g,
|
||||
const Grey &grey) {
|
||||
deque<unique_ptr<NGHolder>> comps;
|
||||
|
||||
// For trivial cases, we needn't bother running the full
|
||||
// connected_components algorithm.
|
||||
if (isAlternationOfClasses(*g)) {
|
||||
if (!grey.calcComponents || isAlternationOfClasses(*g)) {
|
||||
comps.push_back(std::move(g));
|
||||
return comps;
|
||||
}
|
||||
@@ -402,7 +404,11 @@ deque<unique_ptr<NGHolder>> calcComponents(unique_ptr<NGHolder> g) {
|
||||
return comps;
|
||||
}
|
||||
|
||||
void recalcComponents(deque<unique_ptr<NGHolder>> &comps) {
|
||||
void recalcComponents(deque<unique_ptr<NGHolder>> &comps, const Grey &grey) {
|
||||
if (!grey.calcComponents) {
|
||||
return;
|
||||
}
|
||||
|
||||
deque<unique_ptr<NGHolder>> out;
|
||||
|
||||
for (auto &gc : comps) {
|
||||
@@ -415,7 +421,7 @@ void recalcComponents(deque<unique_ptr<NGHolder>> &comps) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto gc_comps = calcComponents(std::move(gc));
|
||||
auto gc_comps = calcComponents(std::move(gc), grey);
|
||||
out.insert(end(out), std::make_move_iterator(begin(gc_comps)),
|
||||
std::make_move_iterator(end(gc_comps)));
|
||||
}
|
||||
|
@@ -39,13 +39,15 @@
|
||||
namespace ue2 {
|
||||
|
||||
class NGHolder;
|
||||
struct Grey;
|
||||
|
||||
bool isAlternationOfClasses(const NGHolder &g);
|
||||
|
||||
std::deque<std::unique_ptr<NGHolder>>
|
||||
calcComponents(std::unique_ptr<NGHolder> g);
|
||||
calcComponents(std::unique_ptr<NGHolder> g, const Grey &grey);
|
||||
|
||||
void recalcComponents(std::deque<std::unique_ptr<NGHolder>> &comps);
|
||||
void recalcComponents(std::deque<std::unique_ptr<NGHolder>> &comps,
|
||||
const Grey &grey);
|
||||
|
||||
} // namespace ue2
|
||||
|
||||
|
Reference in New Issue
Block a user