#include "ng_util.h"
#include "util/compile_context.h"
#include "util/graph_range.h"
+#include "util/make_unique.h"
#include "util/ue2_containers.h"
#include <algorithm>
+#include <memory>
#include <set>
#include <stack>
#include <vector>
-#include <boost/ptr_container/ptr_vector.hpp>
-
using namespace std;
-using boost::ptr_vector;
namespace ue2 {
// populate VertexInfo table
static
-ptr_vector<VertexInfo> getVertexInfos(const NGHolder &g) {
+vector<unique_ptr<VertexInfo>> getVertexInfos(const NGHolder &g) {
const size_t num_verts = num_vertices(g);
- ptr_vector<VertexInfo> infos;
+ vector<unique_ptr<VertexInfo>> infos;
infos.reserve(num_verts * 2);
vector<VertexInfo *> vertex_map; // indexed by vertex_index property
vertex_map.resize(num_verts);
for (auto v : vertices_range(g)) {
- VertexInfo *vi = new VertexInfo(v, g);
-
- // insert our new shiny VertexInfo into the info map
- infos.push_back(vi);
-
- vertex_map[g[v].index] = vi;
+ infos.push_back(make_unique<VertexInfo>(v, g));
+ vertex_map[g[v].index] = infos.back().get();
}
- // now, go through each vertex and populate its predecessor and successor lists
- for (VertexInfo &cur_vi : infos) {
+ // now, go through each vertex and populate its predecessor and successor
+ // lists
+ for (auto &vi : infos) {
+ assert(vi);
+ NFAVertex v = vi->v;
+
// find predecessors
- for (const auto &e : in_edges_range(cur_vi.v, g)) {
+ for (const auto &e : in_edges_range(v, g)) {
NFAVertex u = source(e, g);
- VertexInfo *vmi = vertex_map[g[u].index];
+ VertexInfo *u_vi = vertex_map[g[u].index];
- cur_vi.pred_cr |= vmi->cr;
- cur_vi.pred.insert(vmi);
+ vi->pred_cr |= u_vi->cr;
+ vi->pred.insert(u_vi);
// also set up edge tops
if (is_triggered(g) && u == g.start) {
- cur_vi.edge_tops = g[e].tops;
+ vi->edge_tops = g[e].tops;
}
}
// find successors
- for (auto w : adjacent_vertices_range(cur_vi.v, g)) {
- VertexInfo *vmi = vertex_map[g[w].index];
- cur_vi.succ_cr |= vmi->cr;
- cur_vi.succ.insert(vmi);
+ for (auto w : adjacent_vertices_range(v, g)) {
+ VertexInfo *w_vi = vertex_map[g[w].index];
+ vi->succ_cr |= w_vi->cr;
+ vi->succ.insert(w_vi);
}
- assert(!hasEdgeAsserts(cur_vi.v, g));
+ assert(!hasEdgeAsserts(vi->v, g));
}
return infos;
// store equivalence class in VertexInfo for each vertex
static
-vector<VertexInfoSet> partitionGraph(ptr_vector<VertexInfo> &infos,
+vector<VertexInfoSet> partitionGraph(vector<unique_ptr<VertexInfo>> &infos,
WorkQueue &work_queue, const NGHolder &g,
EquivalenceType eq) {
const size_t num_verts = infos.size();
}
// partition the graph based on CharReach
- for (VertexInfo &vi : infos) {
+ for (auto &vi : infos) {
+ assert(vi);
+
ClassInfo::ClassDepth depth;
if (eq == LEFT_EQUIVALENCE) {
- depth = depths[vi.vert_index];
+ depth = depths[vi->vert_index];
} else {
- depth = rdepths[vi.vert_index];
+ depth = rdepths[vi->vert_index];
}
- ClassInfo ci(g, vi, depth, eq);
+ ClassInfo ci(g, *vi, depth, eq);
auto ii = classinfomap.find(ci);
if (ii == classinfomap.end()) {
// vertex is in a new equivalence class by itself.
unsigned eq_class = classes.size();
- vi.equivalence_class = eq_class;
- classes.push_back({&vi});
+ vi->equivalence_class = eq_class;
+ classes.push_back({vi.get()});
classinfomap.emplace(move(ci), eq_class);
} else {
// vertex is added to an existing class.
unsigned eq_class = ii->second;
- vi.equivalence_class = eq_class;
- classes.at(eq_class).insert(&vi);
+ vi->equivalence_class = eq_class;
+ classes.at(eq_class).insert(vi.get());
// we now know that this particular class has more than one
// vertex, so we add it to the work queue
}
static
-void mergeClass(ptr_vector<VertexInfo> &infos, NGHolder &g, unsigned eq_class,
- VertexInfoSet &cur_class_vertices, set<NFAVertex> *toRemove) {
+void mergeClass(vector<unique_ptr<VertexInfo>> &infos, NGHolder &g,
+ unsigned eq_class, VertexInfoSet &cur_class_vertices,
+ set<NFAVertex> *toRemove) {
DEBUG_PRINTF("Replacing %zd vertices from equivalence class %u with a "
"single vertex.\n", cur_class_vertices.size(), eq_class);
* props */
g[new_v].reports.clear(); /* populated as we pull in succs */
- VertexInfo *new_vertex_info = new VertexInfo(new_v, g);
// store this vertex in our global vertex list
- infos.push_back(new_vertex_info);
+ infos.push_back(make_unique<VertexInfo>(new_v, g));
+ VertexInfo *new_vertex_info = infos.back().get();
NFAVertex new_v_eod = NGHolder::null_vertex();
VertexInfo *new_vertex_info_eod = nullptr;
if (require_separate_eod_vertex(cur_class_vertices, g)) {
new_v_eod = clone_vertex(g, old_v);
g[new_v_eod].reports.clear();
- new_vertex_info_eod = new VertexInfo(new_v_eod, g);
- infos.push_back(new_vertex_info_eod);
+ infos.push_back(make_unique<VertexInfo>(new_v_eod, g));
+ new_vertex_info_eod = infos.back().get();
}
const auto &edgetops = (*cur_class_vertices.begin())->edge_tops;
// report behaviour with a single vertex).
static
bool mergeEquivalentClasses(vector<VertexInfoSet> &classes,
- ptr_vector<VertexInfo> &infos, NGHolder &g) {
+ vector<unique_ptr<VertexInfo>> &infos,
+ NGHolder &g) {
bool merged = false;
set<NFAVertex> toRemove;
// get information on every vertex in the graph
// new vertices are allocated here, and stored in infos
- ptr_vector<VertexInfo> infos = getVertexInfos(g);
+ auto infos = getVertexInfos(g);
// partition the graph
auto classes = partitionGraph(infos, work_queue, g, eq_type);