]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
ng_depth: rename calcDepth functions, return vec
authorJustin Viiret <justin.viiret@intel.com>
Mon, 1 May 2017 04:57:05 +0000 (14:57 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 30 May 2017 03:59:00 +0000 (13:59 +1000)
14 files changed:
src/nfagraph/ng_calc_components.cpp
src/nfagraph/ng_depth.cpp
src/nfagraph/ng_depth.h
src/nfagraph/ng_equivalence.cpp
src/nfagraph/ng_expr_info.cpp
src/nfagraph/ng_extparam.cpp
src/nfagraph/ng_fuzzy.cpp
src/nfagraph/ng_puff.cpp
src/nfagraph/ng_repeat.cpp
src/nfagraph/ng_som_util.cpp
src/nfagraph/ng_stop.cpp
src/nfagraph/ng_violet.cpp
src/rose/rose_build_add.cpp
src/smallwrite/smallwrite_build.cpp

index 54221c7b92afadbea8fb039d98489ab934f596cc..bfe73eb27da9067b3f5e4ad634fe0a8477fc9650 100644 (file)
@@ -235,8 +235,7 @@ void splitIntoComponents(unique_ptr<NGHolder> g,
     *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) {
index 63e0e46b76999a288522c41353f53c6dc9426186..6c45fa2f79311cd304f59031876fb900eeaa755d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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:
@@ -26,7 +26,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/** \file
+/**
+ * \file
  * \brief NFA graph vertex depth calculations.
  */
 #include "ng_depth.h"
@@ -269,12 +270,11 @@ void calcAndStoreDepth(const Graph &g,
     }
 }
 
-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;
 
@@ -291,14 +291,15 @@ void calcDepths(const NGHolder &g, std::vector<NFAVertexDepth> &depths) {
     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;
 
@@ -324,14 +325,15 @@ void calcDepths(const NGHolder &g, std::vector<NFAVertexRevDepth> &depths) {
     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;
 
@@ -366,10 +368,11 @@ void calcDepths(const NGHolder &g, vector<NFAVertexBidiDepth> &depths) {
     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);
 
@@ -379,13 +382,14 @@ void calcDepthsFrom(const NGHolder &g, const NFAVertex src,
     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
index 16231ea1e0e8fe79dfac8830847889abe4519146..36cca87e845e8fb9723eff5aa5ac67fd054eded2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -72,28 +71,29 @@ struct NFAVertexBidiDepth {
 };
 
 /**
- * \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
index b9e2bd0df872d54c0aa6acb4567c927df74ddd4e..f03a662900382dd0e02a2792ad53ce596cc1c4b6 100644 (file)
@@ -342,9 +342,9 @@ vector<VertexInfoSet> partitionGraph(vector<unique_ptr<VertexInfo>> &infos,
     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
index 9417b6743c87c0c996d0575406ede8e8c4a2bba4..6a625ddf7947a7eb3da414f4996765941f0e6179 100644 (file)
@@ -147,8 +147,7 @@ void fillExpressionInfo(ReportManager &rm, NGHolder &g,
     removeLeadingVirtualVerticesFromRoot(g, g.start);
     removeLeadingVirtualVerticesFromRoot(g, g.startDs);
 
-    vector<DepthMinMax> depths;
-    calcDepthsFrom(g, g.start, depths);
+    auto depths = calcDepthsFrom(g, g.start);
 
     DepthMinMax d;
 
index 19fa2295dc5796af97df59c5fb669651d4e3b8e0..bc7f81efd9cf4c1f63ce0546dc21613577f85caa 100644 (file)
@@ -734,8 +734,7 @@ void pruneExtUnreachable(NGHolder &g, const ReportManager &rm) {
 
     const auto &report = rm.getReport(*reports.begin());
 
-    vector<NFAVertexBidiDepth> depths;
-    calcDepths(g, depths);
+    auto depths = calcBidiDepths(g);
 
     vector<NFAEdge> dead;
 
@@ -957,8 +956,7 @@ void replaceMinLengthWithOffset(NGHolder &g, ReportManager &rm) {
  */
 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);
index fc4681261bfdafb5d63d40b3bba3c26146e3958f..2c3d85bd56c1fe5c6d592d6d09fcc35782737e9a 100644 (file)
@@ -603,9 +603,7 @@ private:
 // 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;
index 7281471fccb93dead053183b02c713f7cfc4443d..984518b0fcc21be0915b471b91d029bd61be5c3a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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:
@@ -94,8 +94,7 @@ void wireNewAccepts(NGHolder &g, NFAVertex head,
 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);
@@ -104,8 +103,7 @@ bool isFixedDepth(const NGHolder &g, NFAVertex v) {
         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
index c51618ea6127d6b7714f0e5ab5ef6b575f2013a2..60ad2200956466782d4f67d45d0a90b856267c97 100644 (file)
@@ -118,13 +118,12 @@ struct ReachSubgraph {
 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]);
     }
 }
 
index 78a39119b9a1d6300e5ed66fab29eec075210cb6..a3b6ee5fd201290931896e5983f2c376926d0747 100644 (file)
@@ -78,8 +78,8 @@ vector<DepthMinMax> getDistancesFromSOM(const NGHolder &g_orig) {
 
     //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));
index e601f5411b1f110d5fe2dcf3681a7fa3c519cbc1..c335540acffaf87fef0bc728c3c2b7563c674fda 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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:
@@ -60,10 +60,9 @@ namespace {
 
 /** 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;
index e28256436cf1231658a5ae23c3a35efa5f791783..4195045c4c9a944ddca29b5edeb04f53418a47f7 100644 (file)
@@ -1472,8 +1472,7 @@ void avoidOutfixes(RoseInGraph &vg, bool last_chance,
     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);
 
@@ -1973,8 +1972,7 @@ bool improvePrefix(NGHolder &h, RoseInGraph &vg, const vector<RoseInEdge> &ee,
     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
@@ -2856,8 +2854,7 @@ bool splitForImplementabilty(RoseInGraph &vg, NGHolder &h,
     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 {
index 26f884457b1a7429067d5fff74522c816cd34f48..4c895cafce5c347e7a410df34f7e1b5f28605d82 100644 (file)
@@ -1928,8 +1928,7 @@ void removeAddedLiterals(RoseBuildImpl &tbi, const flat_set<u32> &lit_ids) {
 }
 
 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 */
index 4acfc7133bada364426b745cae2942d6d4ccf9d9..ba2f244dfbdfd3dfc0629e9eae368c19ce777fab 100644 (file)
@@ -198,8 +198,7 @@ static
 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)) {