use NGHolder::foo in favour of NFAGraph::foo

This commit is contained in:
Alex Coyte
2016-07-07 14:07:12 +10:00
committed by Matthew Barr
parent 2471b770a8
commit 691b08d170
29 changed files with 177 additions and 190 deletions

View File

@@ -314,10 +314,8 @@ protected:
// Reverse the graph and add some reports on the accept vertices.
NGHolder g_rev(NFA_REV_PREFIX);
reverseHolder(*g, g_rev);
NFAGraph::inv_adjacency_iterator ai, ae;
for (tie(ai, ae) = inv_adjacent_vertices(g_rev.accept, g_rev); ai != ae;
++ai) {
g_rev[*ai].reports.insert(0);
for (NFAVertex v : inv_adjacent_vertices_range(g_rev.accept, g_rev)) {
g_rev[v].reports.insert(0);
}
nfa = constructReversedNFA(g_rev, type, cc);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -27,7 +27,8 @@
*/
/**
* Unit tests for checking the removeGraphEquivalences code in nfagraph/ng_equivalence.cpp.
* Unit tests for checking the removeGraphEquivalences code in
* nfagraph/ng_equivalence.cpp.
*/
#include "config.h"
@@ -71,10 +72,9 @@ TEST(NFAGraph, RemoveEquivalence1) {
ASSERT_EQ(2U, in_degree(g.accept, g));
// Find a vertex that goes right after startDs
NFAVertex a = NFAGraph::null_vertex();
NFAGraph::adjacency_iterator ai, ae;
for (tie(ai, ae) = adjacent_vertices(g.startDs, g); ai != ae; ++ai) {
a = *ai;
NFAVertex a = NGHolder::null_vertex();
for (NFAVertex v : adjacent_vertices_range(g.startDs, g)) {
a = v;
if (a == g.startDs) {
continue;
}
@@ -87,8 +87,8 @@ TEST(NFAGraph, RemoveEquivalence1) {
ASSERT_TRUE(a != nullptr);
// There should be two edges from v to nodes with reachability 'b' and 'c'
NFAVertex b = NFAGraph::null_vertex();
NFAVertex c = NFAGraph::null_vertex();
NFAVertex b = NGHolder::null_vertex();
NFAVertex c = NGHolder::null_vertex();
for (NFAVertex tmp : adjacent_vertices_range(a, g)) {
const CharReach &tmpcr = g[tmp].char_reach;
ASSERT_EQ(1U, tmpcr.count());
@@ -133,11 +133,9 @@ TEST(NFAGraph, RemoveEquivalence2) {
ASSERT_EQ(1U, in_degree(g.accept, g));
// Find a vertex leading to accept
NFAVertex a = NFAGraph::null_vertex();
NFAGraph::inv_adjacency_iterator ai, ae;
for (tie(ai, ae) = inv_adjacent_vertices(g.accept, g); ai != ae;
++ai) {
a = *ai;
NFAVertex a = NGHolder::null_vertex();
for (NFAVertex v : inv_adjacent_vertices_range(g.accept, g)) {
a = v;
if (a == g.accept) {
continue;
}
@@ -150,8 +148,8 @@ TEST(NFAGraph, RemoveEquivalence2) {
ASSERT_TRUE(a != nullptr);
// There should be two edges from v to nodes with reachability 'b' and 'c'
NFAVertex b = NFAGraph::null_vertex();
NFAVertex c = NFAGraph::null_vertex();
NFAVertex b = NGHolder::null_vertex();
NFAVertex c = NGHolder::null_vertex();
for (NFAVertex tmp : inv_adjacent_vertices_range(a, g)) {
const CharReach &tmpcr = g[tmp].char_reach;
ASSERT_EQ(1U, tmpcr.count());
@@ -197,10 +195,9 @@ TEST(NFAGraph, RemoveEquivalence3) {
ASSERT_EQ(2U, in_degree(g.accept, g));
// Find a vertex 'a' that goes right after startDs
NFAVertex a = NFAGraph::null_vertex();
NFAGraph::adjacency_iterator ai, ae;
for (tie(ai, ae) = adjacent_vertices(g.startDs, g); ai != ae; ++ai) {
a = *ai;
NFAVertex a = NGHolder::null_vertex();
for (NFAVertex v : adjacent_vertices_range(g.startDs, g)) {
a = v;
if (a == g.startDs) {
continue;
}
@@ -234,10 +231,9 @@ TEST(NFAGraph, RemoveEquivalence3) {
ASSERT_TRUE(edge(dot2, dot1, g).second);
// now, let's find X and Y nodes
NFAVertex X = NFAGraph::null_vertex();
NFAVertex Y = NFAGraph::null_vertex();
for (tie(ai, ae) = adjacent_vertices(dot2, g); ai != ae; ++ai) {
NFAVertex tmp = *ai;
NFAVertex X = NGHolder::null_vertex();
NFAVertex Y = NGHolder::null_vertex();
for (NFAVertex tmp : adjacent_vertices_range(dot2, g)) {
// we already know about dot1, so skip it
if (tmp == dot1) {
@@ -290,12 +286,9 @@ TEST(NFAGraph, RemoveEquivalence4) {
ASSERT_EQ(1U, in_degree(g.accept, g));
// Find X and Y nodes that are connected to startDs
NFAVertex X = NFAGraph::null_vertex();
NFAVertex Y = NFAGraph::null_vertex();
NFAGraph::adjacency_iterator ai, ae;
for (tie(ai, ae) = adjacent_vertices(g.startDs, g); ai != ae; ++ai) {
NFAVertex tmp = *ai;
NFAVertex X = NGHolder::null_vertex();
NFAVertex Y = NGHolder::null_vertex();
for (NFAVertex tmp : adjacent_vertices_range(g.startDs, g)) {
// skip startDs
if (tmp == g.startDs) {
continue;
@@ -341,10 +334,8 @@ TEST(NFAGraph, RemoveEquivalence4) {
ASSERT_TRUE(edge(dot2, dot1, g).second);
// now find 'a'
NFAVertex a = NFAGraph::null_vertex();
for (tie(ai, ae) = adjacent_vertices(dot2, g); ai != ae; ++ai) {
NFAVertex tmp = *ai;
NFAVertex a = NGHolder::null_vertex();
for (NFAVertex tmp : adjacent_vertices_range(dot2, g)) {
// skip dot1
if (tmp == dot1) {
continue;
@@ -392,10 +383,9 @@ TEST(NFAGraph, RemoveEquivalence5) {
ASSERT_EQ(1U, in_degree(g.accept, g));
// find first vertex and ensure it has a self loop
NFAVertex v = NFAGraph::null_vertex();
NFAGraph::adjacency_iterator ai, ae;
for (tie(ai, ae) = adjacent_vertices(g.startDs, g); ai != ae; ++ai) {
v = *ai;
NFAVertex v = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(g.startDs, g)) {
v = t;
if (v == g.startDs) {
continue;
}
@@ -409,15 +399,13 @@ TEST(NFAGraph, RemoveEquivalence5) {
ASSERT_TRUE(v != nullptr);
// now, find the vertex leading to accept
NFAVertex v2 = NFAGraph::null_vertex();
for (tie(ai, ae) = adjacent_vertices(v, g); ai != ae; ++ai) {
NFAVertex tmp = *ai;
NFAVertex v2 = NGHolder::null_vertex();
for (NFAVertex tmp : adjacent_vertices_range(v, g)) {
// skip self-loop
if (tmp == v) {
continue;
}
v2 = *ai;
v2 = tmp;
// get char reach
const CharReach tmpcr = g[tmp].char_reach;
@@ -450,10 +438,9 @@ TEST(NFAGraph, RemoveEquivalence6) {
ASSERT_EQ(1U, in_degree(g.accept, g));
// find that vertex and ensure it has no self loops and an edge to accept
NFAVertex v = NFAGraph::null_vertex();
NFAGraph::adjacency_iterator ai, ae;
for (tie(ai, ae) = adjacent_vertices(g.startDs, g); ai != ae; ++ai) {
v = *ai;
NFAVertex v = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(g.startDs, g)) {
v = t;
if (v == g.startDs) {
continue;
}
@@ -492,13 +479,12 @@ TEST(NFAGraph, RemoveEquivalence7) {
ASSERT_EQ(1U, in_degree(g.accept, g));
// find that vertex and ensure it's a dot self loop and has one outgoing edge
NFAVertex v = NFAGraph::null_vertex();
NFAGraph::adjacency_iterator ai, ae;
for (tie(ai, ae) = adjacent_vertices(g.start, g); ai != ae; ++ai) {
if (*ai == g.startDs) {
NFAVertex v = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(g.start, g)) {
if (t == g.startDs) {
continue;
}
v = *ai;
v = t;
// check if it has the right char reach
const CharReach &tmpcr = g[v].char_reach;
ASSERT_TRUE(tmpcr.all());
@@ -509,13 +495,13 @@ TEST(NFAGraph, RemoveEquivalence7) {
ASSERT_TRUE(v != nullptr);
// find the next vertex and ensure it has an edge to accept
NFAVertex v2 = NFAGraph::null_vertex();
for (tie(ai, ae) = adjacent_vertices(v, g); ai != ae; ++ai) {
NFAVertex v2 = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(v, g)) {
// skip self loop
if (*ai == v) {
if (t == v) {
continue;
}
v2 = *ai;
v2 = t;
// check if it has the right char reach
const CharReach &tmpcr = g[v2].char_reach;
ASSERT_EQ(1U, tmpcr.count());

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -27,7 +27,8 @@
*/
/**
* Unit tests for checking the removeRedundancy code in nfagraph/ng_redundancy.cpp.
* Unit tests for checking the removeRedundancy code in
* nfagraph/ng_redundancy.cpp.
*/
#include "config.h"
@@ -62,15 +63,17 @@ TEST(NFAGraph, RemoveRedundancy1) {
// Our graph should only have two non-special nodes
ASSERT_EQ((size_t)N_SPECIALS + 2, num_vertices(*graph));
// Dot-star start state should be connected to itself and a single other vertex
// Dot-star start state should be connected to itself and a single other
// vertex
ASSERT_EQ(2U, out_degree(graph->startDs, g));
// That single vertex should have reachability [ab]
NFAVertex v = NFAGraph::null_vertex();
NFAGraph::adjacency_iterator ai, ae;
for (tie(ai, ae) = adjacent_vertices(graph->startDs, g); ai != ae; ++ai) {
v = *ai;
if (v != graph->startDs) break;
NFAVertex v = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(graph->startDs, g)) {
v = t;
if (v != graph->startDs) {
break;
}
}
const CharReach &cr = g[v].char_reach;
ASSERT_EQ(2U, cr.count());
@@ -103,35 +106,39 @@ TEST(NFAGraph, RemoveRedundancy2) {
// Our graph should now have only 3 non-special vertices
ASSERT_EQ((size_t)N_SPECIALS + 3, num_vertices(*graph));
// Dot-star start state should be connected to itself and a single other vertex
// Dot-star start state should be connected to itself and a single other
// vertex
ASSERT_EQ(2U, out_degree(graph->startDs, g));
// That single vertex should have reachability [a]
NFAVertex v = NFAGraph::null_vertex();
NFAGraph::adjacency_iterator ai, ae;
for (tie(ai, ae) = adjacent_vertices(graph->startDs, g); ai != ae; ++ai) {
v = *ai;
if (v != graph->startDs) break;
NFAVertex v = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(graph->startDs, g)) {
v = t;
if (v != graph->startDs) {
break;
}
}
const CharReach &cr = g[v].char_reach;
ASSERT_EQ(1U, cr.count());
ASSERT_TRUE(cr.test('a'));
// 'a' should have two out edges: one to a dot with a cycle (.*) and one to 'c'
// 'a' should have two out edges: one to a dot with a cycle (.*) and one to
// 'c'
ASSERT_EQ(2U, out_degree(v, g));
NFAVertex dotstar = NFAGraph::null_vertex(), vc = NFAGraph::null_vertex();
for (tie(ai, ae) = adjacent_vertices(v, g); ai != ae; ++ai) {
const CharReach &cr2 = g[*ai].char_reach;
NFAVertex dotstar = NGHolder::null_vertex();
NFAVertex vc = NGHolder::null_vertex();
for (NFAVertex t : adjacent_vertices_range(v, g)) {
const CharReach &cr2 = g[t].char_reach;
if (cr2.count() == 1 && cr2.test('c')) {
vc = *ai;
vc = t;
} else if (cr2.all()) {
dotstar = *ai;
dotstar = t;
} else {
FAIL();
}
}
ASSERT_TRUE(vc != NFAGraph::null_vertex());
ASSERT_TRUE(dotstar != NFAGraph::null_vertex());
ASSERT_TRUE(vc != NGHolder::null_vertex());
ASSERT_TRUE(dotstar != NGHolder::null_vertex());
// Dot-star node should have a self-loop and an edge to vertex 'c'
ASSERT_EQ(2U, out_degree(dotstar, g));

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -85,24 +85,23 @@ TEST(NFAGraph, split1) {
splitGraph(src, pivot, &lhs, &lhs_map, &rhs, &rhs_map);
ASSERT_EQ(3U + N_SPECIALS, num_vertices(lhs));
NFAGraph::vertex_iterator vi, ve;
for (tie(vi, ve) = vertices(lhs); vi != ve; ++vi) {
if (is_special(*vi, lhs)) {
for (NFAVertex v : vertices_range(lhs)) {
if (is_special(v, lhs)) {
continue;
}
u32 cr = lhs[*vi].char_reach.find_first();
u32 cr = lhs[v].char_reach.find_first();
SCOPED_TRACE(cr);
ASSERT_TRUE((cr >= 'a' && cr <= 'c'));
}
ASSERT_EQ(8U + N_SPECIALS, num_vertices(rhs) );
for (tie(vi, ve) = vertices(rhs); vi != ve; ++vi) {
if (is_special(*vi, rhs)) {
for (NFAVertex v : vertices_range(rhs)) {
if (is_special(v, rhs)) {
continue;
}
u32 cr = rhs[*vi].char_reach.find_first();
u32 cr = rhs[v].char_reach.find_first();
SCOPED_TRACE(cr);
ASSERT_TRUE(cr >= 'b' && cr <= 'i');
}
@@ -137,24 +136,23 @@ TEST(NFAGraph, split2) {
splitGraph(src, pivot, &lhs, &lhs_map, &rhs, &rhs_map);
ASSERT_EQ(3U + N_SPECIALS, num_vertices(lhs));
NFAGraph::vertex_iterator vi, ve;
for (tie(vi, ve) = vertices(lhs); vi != ve; ++vi) {
if (is_special(*vi, lhs)) {
for (NFAVertex v : vertices_range(lhs)) {
if (is_special(v, lhs)) {
continue;
}
u32 cr = lhs[*vi].char_reach.find_first();
u32 cr = lhs[v].char_reach.find_first();
SCOPED_TRACE(cr);
ASSERT_TRUE(cr >= 'a' && cr <= 'c');
}
ASSERT_EQ(3U + N_SPECIALS, num_vertices(rhs) );
for (tie(vi, ve) = vertices(rhs); vi != ve; ++vi) {
if (is_special(*vi, rhs)) {
for (NFAVertex v : vertices_range(rhs)) {
if (is_special(v, rhs)) {
continue;
}
u32 cr = rhs[*vi].char_reach.find_first();
u32 cr = rhs[v].char_reach.find_first();
SCOPED_TRACE(cr);
ASSERT_TRUE(cr >= 'b' && cr <= 'd');
}
@@ -211,24 +209,23 @@ TEST(NFAGraph, split3) {
splitGraph(src, pivots, &lhs, &lhs_map, &rhs, &rhs_map);
ASSERT_EQ(7U + N_SPECIALS, num_vertices(lhs));
NFAGraph::vertex_iterator vi, ve;
for (tie(vi, ve) = vertices(lhs); vi != ve; ++vi) {
if (is_special(*vi, lhs)) {
for (NFAVertex v : vertices_range(lhs)) {
if (is_special(v, lhs)) {
continue;
}
u32 cr = lhs[*vi].char_reach.find_first();
u32 cr = lhs[v].char_reach.find_first();
SCOPED_TRACE(cr);
ASSERT_TRUE((cr >= 'a' && cr <= 'g'));
}
ASSERT_EQ(2U + N_SPECIALS, num_vertices(rhs) );
for (tie(vi, ve) = vertices(rhs); vi != ve; ++vi) {
if (is_special(*vi, rhs)) {
for (NFAVertex v : vertices_range(rhs)) {
if (is_special(v, rhs)) {
continue;
}
u32 cr = rhs[*vi].char_reach.find_first();
u32 cr = rhs[v].char_reach.find_first();
SCOPED_TRACE(cr);
ASSERT_TRUE(cr >= 'h' && cr <= 'i');
}
@@ -289,13 +286,12 @@ TEST(NFAGraph, split4) {
splitGraph(src, pivots, &lhs, &lhs_map, &rhs, &rhs_map);
ASSERT_EQ(7U + N_SPECIALS, num_vertices(lhs));
NFAGraph::vertex_iterator vi, ve;
for (tie(vi, ve) = vertices(lhs); vi != ve; ++vi) {
if (is_special(*vi, lhs)) {
for (NFAVertex v : vertices_range(lhs)) {
if (is_special(v, lhs)) {
continue;
}
u32 cr = lhs[*vi].char_reach.find_first();
u32 cr = lhs[v].char_reach.find_first();
SCOPED_TRACE(cr);
ASSERT_TRUE((cr >= 'a' && cr <= 'g'));
}
@@ -304,12 +300,12 @@ TEST(NFAGraph, split4) {
ASSERT_TRUE(edge(lhs_map[d], lhs_map[d], lhs).second);
ASSERT_EQ(2U + N_SPECIALS, num_vertices(rhs) );
for (tie(vi, ve) = vertices(rhs); vi != ve; ++vi) {
if (is_special(*vi, rhs)) {
for (NFAVertex v : vertices_range(rhs)) {
if (is_special(v, rhs)) {
continue;
}
u32 cr = rhs[*vi].char_reach.find_first();
u32 cr = rhs[v].char_reach.find_first();
SCOPED_TRACE(cr);
ASSERT_TRUE(cr >= 'h' && cr <= 'i');
}