From e4b9b94e3938adb560b5febc05a8584fdbb4254d Mon Sep 17 00:00:00 2001 From: dmatetelki Date: Thu, 15 May 2014 15:47:27 +0200 Subject: [PATCH] adjusting iterators after deletion --- lib/graph/graph.hpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/graph/graph.hpp b/lib/graph/graph.hpp index 143ddac..099e827 100644 --- a/lib/graph/graph.hpp +++ b/lib/graph/graph.hpp @@ -6,9 +6,6 @@ #include #include -#include // accumulate -#include -#include template ::removeVertex(const_reference data) if (it == m_vertices.end()) return false; - std::vector neighbours = neighboursOf(data); - std::for_each(neighbours.begin(), neighbours.end(), - [this, &data] (const_reference vertex) - { this->removeAllEdges(vertex, data); } ); + std::for_each(m_vertices.begin(), m_vertices.end(), + [&it] (Vertex& v) + { v.removeAllEdgesTo(it); } ); m_vertices.erase(it); adjustEdges(it); @@ -504,7 +500,7 @@ std::vector::value_type> Graph::neighboursOf(const_re if (vertex_it == m_vertices.end()) return retval; - std::set tmp; + std::set tmp; /// @todo rewrite for_each to parallel aware std::for_each((*vertex_it).m_edges.begin(), (*vertex_it).m_edges.end(), [&tmp, &retval](const EdgeTo& e) @@ -566,13 +562,14 @@ Graph::find(const_reference data) } template -void Graph::adjustEdges(v_iterator /*vit*/) +void Graph::adjustEdges(v_iterator deleted_vit) { -// std::for_each(m_vertices.begin(), m_vertices.end(), -// [&vit](Vertex& v) -// { for (EdgeTo& e : v.m_edges) -// ; /// @bug cannot be done now, wait till the pointer->iterator conversion -// }); + std::for_each(m_vertices.begin(), m_vertices.end(), + [&deleted_vit](Vertex& v) + { for (EdgeTo& e : v.m_edges) + if (e.m_destination > deleted_vit) + --e.m_destination; + }); } #endif // GRAPH_H