Commit 78c7df83 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Move Graph.clear_vertex() fully into C++

parent 7e033535
Pipeline #35 passed with stage
......@@ -184,6 +184,19 @@ void remove_vertex(GraphInterface& gi, size_t v, bool fast)
}
}
struct do_clear_vertex
{
template <class Graph>
void operator()(Graph& g, size_t v) const
{
clear_vertex(vertex(v, g), g);
}
};
void clear_vertex(GraphInterface& gi, size_t v)
{
run_action<>()(gi, std::bind(do_clear_vertex(), placeholders::_1, v))();
}
struct add_new_edge
{
......@@ -505,6 +518,8 @@ struct add_edge_list
for (; iter != end; ++iter)
eprops.emplace_back(*iter, writable_edge_properties());
size_t n_props = std::min(eprops.size(), edge_list.shape()[1] - 2);
for (const auto& e : edge_list)
{
size_t s = e[0];
......@@ -512,7 +527,7 @@ struct add_edge_list
while (s >= num_vertices(g) || t >= num_vertices(g))
add_vertex(g);
auto ne = add_edge(vertex(s, g), vertex(t, g), g).first;
for (size_t i = 0; i < e.size() - 2; ++i)
for (size_t i = 0; i < n_props; ++i)
{
try
{
......@@ -918,6 +933,7 @@ void export_python_interface()
def("add_vertex", graph_tool::add_vertex);
def("add_edge", graph_tool::add_edge);
def("remove_vertex", graph_tool::remove_vertex);
def("clear_vertex", graph_tool::clear_vertex);
def("remove_edge", graph_tool::remove_edge);
def("add_edge_list", graph_tool::do_add_edge_list);
def("add_edge_list_hashed", graph_tool::do_add_edge_list_hashed);
......
......@@ -1845,11 +1845,7 @@ class Graph(object):
def clear_vertex(self, vertex):
"""Remove all in and out-edges from the given vertex."""
del_es = set()
for e in vertex.all_edges():
del_es.add(e)
for e in del_es:
self.remove_edge(e)
libcore.clear_vertex(self.__graph, int(vertex))
def add_edge(self, source, target, add_missing=True):
"""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