Commit a962d139 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Properly remove in- and out-edges when vertex is removed

The edge index housekeeping was not performed on edges which were
deleted due to vertex removal.
parent ff5db995
......@@ -158,27 +158,6 @@ degree(typename graph_traits<GraphWrap<Graph> >::vertex_descriptor u,
return degree(u, g._g);
}
template <class Graph>
inline typename graph_traits<GraphWrap<Graph> >::vertex_descriptor
add_vertex(GraphWrap<Graph>& g)
{
return add_vertex(g._g);
}
template <class Graph>
inline void clear_vertex(typename graph_traits<GraphWrap<Graph> >::vertex_descriptor u,
GraphWrap<Graph>& g)
{
clear_vertex(u, g._g);
}
template <class Graph>
inline void remove_vertex(typename graph_traits<GraphWrap<Graph> >::vertex_descriptor u,
GraphWrap<Graph>& g)
{
remove_vertex(u, g._g);
}
template <class Graph>
inline std::pair<typename graph_traits<GraphWrap<Graph> >::edge_descriptor, bool>
add_edge(typename graph_traits<GraphWrap<Graph> >::vertex_descriptor u,
......@@ -215,6 +194,41 @@ inline void remove_edge(typename graph_traits<GraphWrap<Graph> >::vertex_descrip
}
template <class Graph>
inline typename graph_traits<GraphWrap<Graph> >::vertex_descriptor
add_vertex(GraphWrap<Graph>& g)
{
return add_vertex(g._g);
}
template <class Graph>
inline void clear_vertex(typename graph_traits<GraphWrap<Graph> >::vertex_descriptor u,
GraphWrap<Graph>& g)
{
typedef GraphWrap<Graph> graph_t;
vector<typename graph_traits<graph_t>::edge_descriptor> del_es;
typename graph_traits<graph_t>::out_edge_iterator e, e_end;
for (tie(e,e_end) == out_edges(u, g); e != e_end; ++e)
del_es.push_back(*e);
if (is_directed::apply<graph_t>::type::value)
{
typename in_edge_iteratorS<graph_t>::type e, e_end;
for (tie(e,e_end) == in_edge_iteratorS<graph_t>::get_edges(u, g);
e != e_end; ++e)
del_es.push_back(*e);
}
for (size_t i = 0; i < del_es.size(); ++i)
remove_edge(del_es[i], g);
}
template <class Graph>
inline void remove_vertex(typename graph_traits<GraphWrap<Graph> >::vertex_descriptor u,
GraphWrap<Graph>& g)
{
clear_vertex(u, g);
remove_vertex(u, g._g);
}
template <class Graph, class Predicate>
inline void
remove_out_edge_if(typename graph_traits<GraphWrap<Graph> >::vertex_descriptor u,
......
......@@ -318,6 +318,7 @@ class Graph(object):
if pmap[0] == "v" and pmap[1]() != None and \
pmap[1]() != self.__vertex_index._PropertyMap__map:
self.__graph.ShiftVertexProperty(pmap[1]().get_map(), index)
self.clear_vertex(vertex)
self.__graph.RemoveVertex(vertex)
@_handle_exceptions
......@@ -330,6 +331,15 @@ class Graph(object):
if predicate(v):
self.remove_vertex(v)
@_handle_exceptions
def clear_vertex(self, vertex):
"""Removes all in and out-edges from the given vertex."""
del_es = []
for e in vertex.all_edges():
del_es.append(e)
for e in del_es:
self.remove_edge(e)
@_handle_exceptions
def add_edge(self, source, target):
"""Add a new edge from 'source' to 'target' to the graph, and return
......
Supports Markdown
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