adjusting iterators after deletion

for/release
dmatetelki 11 years ago
parent 37862e6242
commit e4b9b94e39

@ -6,9 +6,6 @@
#include <set> #include <set>
#include <algorithm> #include <algorithm>
#include <numeric> // accumulate
#include <iterator>
#include <memory>
template <typename V, template <typename V,
@ -47,7 +44,7 @@ private:
void swap(EdgeTo& o); void swap(EdgeTo& o);
bool operator==(const EdgeTo& o) const; bool operator==(const EdgeTo& o) const;
v_iterator m_destination; v_const_iterator m_destination;
weight_type m_weight; weight_type m_weight;
}; };
@ -421,10 +418,9 @@ inline bool Graph<V, E>::removeVertex(const_reference data)
if (it == m_vertices.end()) if (it == m_vertices.end())
return false; return false;
std::vector<value_type> neighbours = neighboursOf(data); std::for_each(m_vertices.begin(), m_vertices.end(),
std::for_each(neighbours.begin(), neighbours.end(), [&it] (Vertex& v)
[this, &data] (const_reference vertex) { v.removeAllEdgesTo(it); } );
{ this->removeAllEdges(vertex, data); } );
m_vertices.erase(it); m_vertices.erase(it);
adjustEdges(it); adjustEdges(it);
@ -504,7 +500,7 @@ std::vector<typename Graph<V, E>::value_type> Graph<V, E>::neighboursOf(const_re
if (vertex_it == m_vertices.end()) if (vertex_it == m_vertices.end())
return retval; return retval;
std::set<v_iterator> tmp; std::set<v_const_iterator> tmp;
/// @todo rewrite for_each to parallel aware /// @todo rewrite for_each to parallel aware
std::for_each((*vertex_it).m_edges.begin(), (*vertex_it).m_edges.end(), std::for_each((*vertex_it).m_edges.begin(), (*vertex_it).m_edges.end(),
[&tmp, &retval](const EdgeTo& e) [&tmp, &retval](const EdgeTo& e)
@ -566,13 +562,14 @@ Graph<V, E>::find(const_reference data)
} }
template <typename V, typename E> template <typename V, typename E>
void Graph<V, E>::adjustEdges(v_iterator /*vit*/) void Graph<V, E>::adjustEdges(v_iterator deleted_vit)
{ {
// std::for_each(m_vertices.begin(), m_vertices.end(), std::for_each(m_vertices.begin(), m_vertices.end(),
// [&vit](Vertex& v) [&deleted_vit](Vertex& v)
// { for (EdgeTo& e : v.m_edges) { for (EdgeTo& e : v.m_edges)
// ; /// @bug cannot be done now, wait till the pointer->iterator conversion if (e.m_destination > deleted_vit)
// }); --e.m_destination;
});
} }
#endif // GRAPH_H #endif // GRAPH_H

Loading…
Cancel
Save