Commit 31373d8f authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix Graph.clear() and Graph.clear_edges() behavior for filtered graphs

parent eb743ada
......@@ -79,15 +79,38 @@ size_t GraphInterface::GetNumberOfEdges()
return n;
}
struct clear_vertices
{
template <class Graph>
void operator()(Graph& g) const
{
int N = num_vertices(g);
for (int i = N - 1; i >= 0; --i)
{
auto v = vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
continue;
remove_vertex(v, g);
}
}
};
void GraphInterface::Clear()
{
*_mg = multigraph_t();
run_action<>()(*this, std::bind(clear_vertices(), placeholders::_1))();
}
struct clear_edges
{
template <class Graph>
void operator()(Graph& g) const
{
for (auto v : vertices_range(g))
clear_vertex(v, g);
}
};
void GraphInterface::ClearEdges()
{
graph_traits<multigraph_t>::vertex_iterator v, v_end;
for (tie(v, v_end) = vertices(*_mg); v != v_end; ++v)
clear_vertex(*v, *_mg);
_mg->reindex_edges();
run_action<>()(*this, std::bind(clear_edges(), placeholders::_1))();
}
......@@ -561,6 +561,17 @@ inline void remove_vertex
remove_vertex(u, g.OriginalGraph());
}
//==============================================================================
// remove_vertex_fast(u,g)
//==============================================================================
template <class Graph>
inline void remove_vertex_fast
(typename graph_traits<UndirectedAdaptor<Graph> >::vertex_descriptor u,
UndirectedAdaptor<Graph>& g)
{
remove_vertex_fast(u, g.OriginalGraph());
}
//==============================================================================
// add_edge(u,v,g)
//==============================================================================
......
......@@ -39,6 +39,8 @@
#include <functional>
#include <random>
#include "graph_selectors.hh"
namespace graph_tool
{
......@@ -225,7 +227,12 @@ clear_vertex(typename boost::graph_traits
<filtered_graph<Graph,EdgePredicate,VertexPredicate>>::vertex_descriptor v,
filtered_graph<Graph,EdgePredicate,VertexPredicate>& g)
{
return clear_vertex(v, const_cast<Graph&>(g.m_g));
typedef typename boost::graph_traits<filtered_graph<Graph,EdgePredicate,VertexPredicate>>::edge_descriptor e_t;
std::vector<e_t> e_list;
for (auto e : graph_tool::all_edges_range(v, g))
e_list.push_back(e);
for (auto& e : e_list)
remove_edge(e, g);
}
//==============================================================================
......@@ -270,26 +277,72 @@ void remove_edge(typename boost::graph_traits
return remove_edge(e,const_cast<Graph&>(g.m_g));
}
//==============================================================================
//remove_vertex(v, filtered_graph<G>)
//==============================================================================
template <class Graph, class EdgePredicate, class VertexPredicate>
inline
void remove_vertex(typename boost::graph_traits
<filtered_graph<Graph,EdgePredicate,
VertexPredicate>>::vertex_descriptor v,
filtered_graph<Graph,EdgePredicate,VertexPredicate>& g)
{
return remove_vertex(v,const_cast<Graph&>(g.m_g));
}
//==============================================================================
//remove_vertex_fast(v, filtered_graph<G>)
//==============================================================================
template <class Graph, class EdgePredicate, class VertexPredicate>
inline
void remove_vertex_fast(typename boost::graph_traits
<filtered_graph<Graph,EdgePredicate,
VertexPredicate>>::vertex_descriptor v,
filtered_graph<Graph,EdgePredicate,VertexPredicate>& g)
{
return remove_vertex_fast(v,const_cast<Graph&>(g.m_g));
}
//==============================================================================
//remove_edge(e, reverse_graph<G>)
//==============================================================================
template <class Graph>
inline
void remove_edge
(typename boost::graph_traits<reverse_graph<Graph>>::edge_descriptor e,
reverse_graph<Graph>& g)
void remove_edge(typename boost::graph_traits<reverse_graph<Graph>>::edge_descriptor e,
reverse_graph<Graph>& g)
{
return remove_edge(e,const_cast<Graph&>(g.m_g));
}
//==============================================================================
//remove_vertex(v, reverse_graph<G>)
//==============================================================================
template <class Graph>
inline
void remove_vertex(typename boost::graph_traits<reverse_graph<Graph>>::vertex_descriptor v,
reverse_graph<Graph>& g)
{
return remove_vertex(v,const_cast<Graph&>(g.m_g));
}
//==============================================================================
//remove_vertex_fast(v, reverse_graph<G>)
//==============================================================================
template <class Graph>
inline
void remove_vertex_fast(typename boost::graph_traits<reverse_graph<Graph>>::vertex_descriptor v,
reverse_graph<Graph>& g)
{
return remove_vertex_fast(v,const_cast<Graph&>(g.m_g));
}
//==============================================================================
//clear_vertex(v, reverse_graph<G>)
//==============================================================================
template <class Graph>
inline
void clear_vertex
(typename boost::graph_traits<reverse_graph<Graph>>::vertex_descriptor v,
reverse_graph<Graph>& g)
void clear_vertex(typename boost::graph_traits<reverse_graph<Graph>>::vertex_descriptor v,
reverse_graph<Graph>& g)
{
return clear_vertex(v,const_cast<Graph&>(g.m_g));
}
......
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