Commit 172e1326 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Improve edge re-indexing complexity

It was needlessly O(E^2), and now is O(E).
parent 7c957a60
......@@ -217,11 +217,12 @@ void GraphInterface::ReIndexEdges()
for (tie(e, e_end) = out_edges(*v, _mg); e != e_end; ++e)
{
size_t index = _edge_index[*e];
if (index >= num_edges(_mg))
if (index >= n_edges)
continue;
if (index >= edge_map.size())
edge_map.resize(index+1, make_pair(edge_t(), false));
edge_map[index] = make_pair(*e, true);
if (!edge_map[index].second)
edge_map[index] = make_pair(*e, true);
}
size_t new_index = 0;
......@@ -236,7 +237,7 @@ void GraphInterface::ReIndexEdges()
edge_t old_edge = edge_map[new_index].first;
if (edge_map[new_index].second &&
_edge_index[*e] != _edge_index[old_edge])
(_edge_index[*e] != _edge_index[old_edge]))
{
// another edge exists with the same (new) index; the properties
// must be swapped
......
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