Commit 60acdcfa authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Include Graph.reindex_edges() and Graph.max_edge_index

These functions/properties provide more information and control about
edge indexing, which might be useful.
parent 2baba488
......@@ -367,6 +367,7 @@ BOOST_PYTHON_MODULE(libgraph_tool_core)
.def("GetVertexIndex", &GraphInterface::GetVertexIndex)
.def("GetEdgeIndex", &GraphInterface::GetEdgeIndex)
.def("GetMaxEdgeIndex", &GraphInterface::GetMaxEdgeIndex)
.def("ReIndexEdges", &GraphInterface::ReIndexEdges)
.def("GetGraphIndex", &GraphInterface::GetGraphIndex)
.def("CopyVertexProperty", &GraphInterface::CopyVertexProperty)
.def("CopyEdgeProperty", &GraphInterface::CopyEdgeProperty);
......
......@@ -210,11 +210,9 @@ bool GraphInterface::IsEdgeFilterActive() const
void GraphInterface::ReIndexEdges()
{
size_t index = 0;
graph_traits<multigraph_t>::vertex_iterator v, v_end;
graph_traits<multigraph_t>::out_edge_iterator e, e_end;
for (tie(v, v_end) = vertices(_mg); v != v_end; ++v)
for (tie(e, e_end) = out_edges(*v, _mg); e != e_end; ++e)
_edge_index[*e] = index++;
graph_traits<multigraph_t>::edge_iterator e, e_end;
for (tie(e, e_end) = edges( _mg); e != e_end; ++e)
_edge_index[*e] = index++;
_max_edge_index = (index > 0) ? index - 1 : 0;
_nedges = index;
_free_indexes.clear();
......
......@@ -696,6 +696,26 @@ class Graph(object):
return self.__edge_index
edge_index = property(_get_edge_index, doc="Edge index map.")
def _get_max_edge_index(self):
return self.__graph.GetMaxEdgeIndex()
max_edge_index = property(_get_max_edge_index,
doc="The maximum value of the edge index map.")
def reindex_edges(self):
"""
Reset the edge indexes so that they lie in the [0, :meth:`~graph_tool.Graph.num_edges` - 1]
range. The index ordering will be compatible with the sequence returned
by the :meth:`~graph_tool.Graph.edges` function.
.. WARNING::
Calling this function will invalidate all existing edge property
maps, if the index ordering is modified! The property maps will still
be usable, but their contents will still be tied to the old indices,
and thus may be scrambled.
"""
self.__graph.ReIndexEdges()
# Property map creation
def new_property(self, key_type, value_type):
......
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