Commit 2de7ad34 authored by Tiago Peixoto's avatar Tiago Peixoto

graph_parallel.hh: cosmetic functor -> function conversion

parent 2b51e4b5
...@@ -36,7 +36,7 @@ void do_label_parallel_edges(GraphInterface& gi, boost::any property, ...@@ -36,7 +36,7 @@ void do_label_parallel_edges(GraphInterface& gi, boost::any property,
(gi, (gi,
[&](auto&& graph, auto&& a2) [&](auto&& graph, auto&& a2)
{ {
return label_parallel_edges() return label_parallel_edges
(std::forward<decltype(graph)>(graph), (std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2), mark_only); std::forward<decltype(a2)>(a2), mark_only);
}, },
...@@ -50,7 +50,7 @@ void do_label_self_loops(GraphInterface& gi, boost::any property, ...@@ -50,7 +50,7 @@ void do_label_self_loops(GraphInterface& gi, boost::any property,
(gi, (gi,
[&](auto&& graph, auto&& a2) [&](auto&& graph, auto&& a2)
{ {
return label_self_loops() return label_self_loops
(std::forward<decltype(graph)>(graph), (std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2), mark_only); std::forward<decltype(a2)>(a2), mark_only);
}, },
...@@ -63,7 +63,7 @@ void do_remove_labeled_edges(GraphInterface& gi, boost::any property) ...@@ -63,7 +63,7 @@ void do_remove_labeled_edges(GraphInterface& gi, boost::any property)
(gi, (gi,
[&](auto&& graph, auto&& a2) [&](auto&& graph, auto&& a2)
{ {
return remove_labeled_edges() return remove_labeled_edges
(std::forward<decltype(graph)>(graph), (std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2)); std::forward<decltype(a2)>(a2));
}, },
......
...@@ -28,109 +28,100 @@ using namespace std; ...@@ -28,109 +28,100 @@ using namespace std;
using namespace boost; using namespace boost;
// label parallel edges in the order they are found, starting from 1 // label parallel edges in the order they are found, starting from 1
struct label_parallel_edges template <class Graph, class ParallelMap>
void label_parallel_edges(const Graph& g, ParallelMap parallel, bool mark_only)
{ {
template <class Graph, class ParallelMap> typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
void operator()(const Graph& g, ParallelMap parallel, bool mark_only) const typedef typename graph_traits<Graph>::edge_descriptor edge_t;
{ typename property_map<Graph, edge_index_t>::type eidx = get(edge_index, g);
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef typename graph_traits<Graph>::edge_descriptor edge_t;
typename property_map<Graph, edge_index_t>::type eidx = get(edge_index, g);
idx_map<vertex_t, edge_t> vset; idx_map<vertex_t, edge_t> vset;
idx_map<size_t, bool> self_loops; idx_map<size_t, bool> self_loops;
#pragma omp parallel if (num_vertices(g) > OPENMP_MIN_THRESH) \ #pragma omp parallel if (num_vertices(g) > OPENMP_MIN_THRESH) \
firstprivate(vset) firstprivate(self_loops) firstprivate(vset) firstprivate(self_loops)
parallel_vertex_loop_no_spawn parallel_vertex_loop_no_spawn
(g, (g,
[&](auto v) [&](auto v)
{
for (auto e : out_edges_range(v, g))
{ {
for (auto e : out_edges_range(v, g)) vertex_t u = target(e, g);
{
vertex_t u = target(e, g);
// do not visit edges twice in undirected graphs // do not visit edges twice in undirected graphs
if (!graph_tool::is_directed(g) && u < v) if (!graph_tool::is_directed(g) && u < v)
continue; continue;
if (u == v) if (u == v)
{ {
if (self_loops[eidx[e]]) if (self_loops[eidx[e]])
continue; continue;
self_loops[eidx[e]] = true; self_loops[eidx[e]] = true;
} }
auto iter = vset.find(u); auto iter = vset.find(u);
if (iter == vset.end()) if (iter == vset.end())
{
vset[u] = e;
}
else
{
if (mark_only)
{ {
vset[u] = e; parallel[e] = true;
} }
else else
{ {
if (mark_only) parallel[e] = parallel[iter->second] + 1;
{ vset[u] = e;
parallel[e] = true;
}
else
{
parallel[e] = parallel[iter->second] + 1;
vset[u] = e;
}
} }
} }
vset.clear(); }
self_loops.clear(); vset.clear();
}); self_loops.clear();
} });
}; }
// label self loops edges in the order they are found, starting from 1 // label self loops edges in the order they are found, starting from 1
struct label_self_loops template <class Graph, class SelfMap>
void label_self_loops(const Graph& g, SelfMap self, bool mark_only)
{ {
template <class Graph, class SelfMap> parallel_vertex_loop
void operator()(const Graph& g, SelfMap self, bool mark_only) const (g,
{ [&](auto v)
parallel_vertex_loop {
(g, size_t n = 1;
[&](auto v) for (auto e : out_edges_range(v, g))
{ {
size_t n = 1; if (target(e, g) == v)
for (auto e : out_edges_range(v, g)) put(self, e, mark_only ? 1 : n++);
{ else
if (target(e, g) == v) put(self, e, 0);
put(self, e, mark_only ? 1 : n++); }
else });
put(self, e, 0);
}
});
}
}; };
// remove edges with label larger than 0 // remove edges with label larger than 0
struct remove_labeled_edges template <class Graph, class LabelMap>
void remove_labeled_edges(Graph& g, LabelMap label)
{ {
template <class Graph, class LabelMap> typedef typename graph_traits<Graph>::edge_descriptor edge_t;
void operator()(Graph& g, LabelMap label) const vector<edge_t> r_edges;
for (auto v : vertices_range(g))
{ {
typedef typename graph_traits<Graph>::edge_descriptor edge_t; for (auto e : out_edges_range(v, g))
vector<edge_t> r_edges;
for (auto v : vertices_range(g))
{ {
for (auto e : out_edges_range(v, g)) if (label[e] > 0)
{ r_edges.push_back(e);
if (label[e] > 0) }
r_edges.push_back(e);
}
while (!r_edges.empty()) while (!r_edges.empty())
{ {
remove_edge(r_edges.back(), g); remove_edge(r_edges.back(), g);
r_edges.pop_back(); r_edges.pop_back();
}
} }
} }
}; }
} // graph_tool namespace } // graph_tool namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment