*shell_comp = false;
// Compute "shell" head and tail subgraphs.
- vector<NFAVertexBidiDepth> depths;
- calcDepths(*g, depths);
+ auto depths = calcBidiDepths(*g);
auto head_shell = findHeadShell(*g, depths, max_head_depth);
auto tail_shell = findTailShell(*g, depths, max_tail_depth);
for (auto v : head_shell) {
/*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* POSSIBILITY OF SUCH DAMAGE.
*/
-/** \file
+/**
+ * \file
* \brief NFA graph vertex depth calculations.
*/
#include "ng_depth.h"
}
}
-void calcDepths(const NGHolder &g, std::vector<NFAVertexDepth> &depths) {
+vector<NFAVertexDepth> calcDepths(const NGHolder &g) {
assert(hasCorrectlyNumberedVertices(g));
const size_t numVertices = num_vertices(g);
- depths.clear();
- depths.resize(numVertices);
+ vector<NFAVertexDepth> depths(numVertices);
vector<int> dMin;
vector<int> dMax;
DEBUG_PRINTF("doing startds\n");
calcAndStoreDepth(g, g.startDs, deadNodes, dMin, dMax, depths,
&NFAVertexDepth::fromStartDotStar);
+
+ return depths;
}
-void calcDepths(const NGHolder &g, std::vector<NFAVertexRevDepth> &depths) {
+vector<NFAVertexRevDepth> calcRevDepths(const NGHolder &g) {
assert(hasCorrectlyNumberedVertices(g));
const size_t numVertices = num_vertices(g);
- depths.clear();
- depths.resize(numVertices);
+ vector<NFAVertexRevDepth> depths(numVertices);
vector<int> dMin;
vector<int> dMax;
calcAndStoreDepth<RevNFAGraph, NFAVertexRevDepth>(
rg, g.acceptEod, deadNodes, dMin, dMax, depths,
&NFAVertexRevDepth::toAcceptEod);
+
+ return depths;
}
-void calcDepths(const NGHolder &g, vector<NFAVertexBidiDepth> &depths) {
+vector<NFAVertexBidiDepth> calcBidiDepths(const NGHolder &g) {
assert(hasCorrectlyNumberedVertices(g));
const size_t numVertices = num_vertices(g);
- depths.clear();
- depths.resize(numVertices);
+ vector<NFAVertexBidiDepth> depths(numVertices);
vector<int> dMin;
vector<int> dMax;
calcAndStoreDepth<RevNFAGraph, NFAVertexBidiDepth>(
rg, g.acceptEod, deadNodes, dMin, dMax, depths,
&NFAVertexBidiDepth::toAcceptEod);
+
+ return depths;
}
-void calcDepthsFrom(const NGHolder &g, const NFAVertex src,
- vector<DepthMinMax> &depths) {
+vector<DepthMinMax> calcDepthsFrom(const NGHolder &g, const NFAVertex src) {
assert(hasCorrectlyNumberedVertices(g));
const size_t numVertices = num_vertices(g);
vector<int> dMin, dMax;
calcDepthFromSource(g, src, deadNodes, dMin, dMax);
- depths.clear();
- depths.resize(numVertices);
+ vector<DepthMinMax> depths(numVertices);
for (auto v : vertices_range(g)) {
- u32 idx = g[v].index;
+ auto idx = g[v].index;
depths.at(idx) = getDepths(idx, dMin, dMax);
}
+
+ return depths;
}
} // namespace ue2
/*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* POSSIBILITY OF SUCH DAMAGE.
*/
-/** \file
+/**
+ * \file
* \brief NFA graph vertex depth calculations.
*/
-#ifndef STRUCTURAL_ANALYSIS_H
-#define STRUCTURAL_ANALYSIS_H
+#ifndef NG_DEPTH_H
+#define NG_DEPTH_H
-#include "nfagraph/ng_holder.h"
#include "ue2common.h"
+#include "nfagraph/ng_holder.h"
#include "util/depth.h"
#include <vector>
namespace ue2 {
-class NGHolder;
-
/**
* \brief Encapsulates min/max depths relative to the start and startDs
* vertices.
};
/**
- * \brief Calculate depths from start and startDs.
- * Fills the vector \p depths (indexed by \p vertex_index).
+ * \brief Calculate depths from start and startDs. Returns them in a vector,
+ * indexed by vertex index.
*/
-void calcDepths(const NGHolder &g, std::vector<NFAVertexDepth> &depths);
+std::vector<NFAVertexDepth> calcDepths(const NGHolder &g);
/**
- * \brief Calculate depths to accept and acceptEod.
- * Fills the vector \p depths (indexed by \p vertex_index).
+ * \brief Calculate depths to accept and acceptEod. Returns them in a vector,
+ * indexed by vertex index.
*/
-void calcDepths(const NGHolder &g, std::vector<NFAVertexRevDepth> &depths);
+std::vector<NFAVertexRevDepth> calcRevDepths(const NGHolder &g);
/**
- * \brief Calculate depths to/from all special vertices.
- * Fills the vector \p depths (indexed by \p vertex_index).
+ * \brief Calculate depths to/from all special vertices. Returns them in a
+ * vector, indexed by vertex index.
*/
-void calcDepths(const NGHolder &g, std::vector<NFAVertexBidiDepth> &depths);
+std::vector<NFAVertexBidiDepth> calcBidiDepths(const NGHolder &g);
-/** Calculate the (min, max) depths from the given \p src to every vertex in
- * the graph and return them in a vector, indexed by \p vertex_index. */
-void calcDepthsFrom(const NGHolder &g, const NFAVertex src,
- std::vector<DepthMinMax> &depths);
+/**
+ * \brief Calculate the (min, max) depths from the given \p src to every vertex
+ * in the graph and return them in a vector, indexed by \p vertex_index.
+ */
+std::vector<DepthMinMax> calcDepthsFrom(const NGHolder &g, const NFAVertex src);
} // namespace ue2
-#endif
+#endif // NG_DEPTH_H
vector<NFAVertexRevDepth> rdepths;
if (eq == LEFT_EQUIVALENCE) {
- calcDepths(g, depths);
+ depths = calcDepths(g);
} else {
- calcDepths(g, rdepths);
+ rdepths = calcRevDepths(g);
}
// partition the graph based on CharReach
removeLeadingVirtualVerticesFromRoot(g, g.start);
removeLeadingVirtualVerticesFromRoot(g, g.startDs);
- vector<DepthMinMax> depths;
- calcDepthsFrom(g, g.start, depths);
+ auto depths = calcDepthsFrom(g, g.start);
DepthMinMax d;
const auto &report = rm.getReport(*reports.begin());
- vector<NFAVertexBidiDepth> depths;
- calcDepths(g, depths);
+ auto depths = calcBidiDepths(g);
vector<NFAEdge> dead;
*/
static
void removeUnneededOffsetBounds(NGHolder &g, ReportManager &rm) {
- vector<NFAVertexDepth> depths;
- calcDepths(g, depths);
+ auto depths = calcDepths(g);
replaceReports(g, [&](NFAVertex v, ReportID id) {
const auto &d = depths.at(g[v].index);
// check if we will edit our way into a vacuous pattern
static
bool will_turn_vacuous(const NGHolder &g, u32 edit_distance) {
- vector<NFAVertexRevDepth> depths;
-
- calcDepths(g, depths);
+ auto depths = calcRevDepths(g);
depth min_depth = depth::infinity();
auto idx = g[g.start].index;
/*
- * Copyright (c) 2015-2016, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
static
bool isFixedDepth(const NGHolder &g, NFAVertex v) {
// If the vertex is reachable from startDs, it can't be fixed depth.
- vector<DepthMinMax> depthFromStartDs;
- calcDepthsFrom(g, g.startDs, depthFromStartDs);
+ auto depthFromStartDs = calcDepthsFrom(g, g.startDs);
u32 idx = g[v].index;
const DepthMinMax &ds = depthFromStartDs.at(idx);
return false;
}
- vector<DepthMinMax> depthFromStart;
- calcDepthsFrom(g, g.start, depthFromStart);
+ auto depthFromStart = calcDepthsFrom(g, g.start);
/* we can still consider the head of a puff chain as at fixed depth if
* it has a self-loop: so we look at all the preds of v (other than v
static
void findInitDepths(const NGHolder &g,
ue2::unordered_map<NFAVertex, NFAVertexDepth> &depths) {
- vector<NFAVertexDepth> d;
- calcDepths(g, d);
+ auto d = calcDepths(g);
for (auto v : vertices_range(g)) {
- u32 idx = g[v].index;
+ size_t idx = g[v].index;
assert(idx < d.size());
- depths.insert(make_pair(v, d[idx]));
+ depths.emplace(v, d[idx]);
}
}
//dumpGraph("som_depth.dot", g);
- vector<DepthMinMax> temp_depths; // numbered by vertex index in g
- calcDepthsFrom(g, g.start, temp_depths);
+ // Find depths, indexed by vertex index in g
+ auto temp_depths = calcDepthsFrom(g, g.start);
// Transfer depths, indexed by vertex index in g_orig.
vector<DepthMinMax> depths(num_vertices(g_orig));
/*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
/** Depths from start, startDs for this graph. */
struct InitDepths {
- explicit InitDepths(const NGHolder &g) {
- calcDepthsFrom(g, g.start, start);
- calcDepthsFrom(g, g.startDs, startDs);
- }
+ explicit InitDepths(const NGHolder &g)
+ : start(calcDepthsFrom(g, g.start)),
+ startDs(calcDepthsFrom(g, g.startDs)) {}
depth maxDist(const NGHolder &g, NFAVertex v) const {
u32 idx = g[v].index;
if (last_chance) {
/* look for a prefix split as it allows us to accept very weak anchored
* literals. */
- vector<NFAVertexDepth> depths;
- calcDepths(h, depths);
+ auto depths = calcDepths(h);
split = findBestPrefixSplit(h, depths, vg, {e}, last_chance, cc);
renumber_vertices(h);
renumber_edges(h);
- vector<NFAVertexDepth> depths;
- calcDepths(h, depths);
+ auto depths = calcDepths(h);
/* If the reason the prefix is not transient is due to a very long literal
* following, we can make it transient by restricting ourselves to using
unique_ptr<VertLitInfo> split;
bool last_chance = true;
if (h.kind == NFA_PREFIX) {
- vector<NFAVertexDepth> depths;
- calcDepths(h, depths);
+ auto depths = calcDepths(h);
split = findBestPrefixSplit(h, depths, vg, edges, last_chance, cc);
} else {
}
bool RoseBuildImpl::addAnchoredAcyclic(const NGHolder &h) {
- vector<DepthMinMax> vertexDepths;
- calcDepthsFrom(h, h.start, vertexDepths);
+ auto vertexDepths = calcDepthsFrom(h, h.start);
map<NFAVertex, set<u32> > reportMap; /* NFAVertex -> literal ids */
map<u32, DepthMinMax> depthMap; /* literal id -> min/max depth */
bool pruneOverlong(NGHolder &g, const depth &max_depth,
const ReportManager &rm) {
bool modified = false;
- std::vector<NFAVertexDepth> depths;
- calcDepths(g, depths);
+ auto depths = calcDepths(g);
for (auto v : vertices_range(g)) {
if (is_special(v, g)) {