mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
ng_depth: rename calcDepth functions, return vec
This commit is contained in:
parent
15c8a7bd98
commit
dfe1b8a2af
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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,23 +26,22 @@
|
||||
* 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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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 */
|
||||
|
@ -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)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user