Edge stores value_type not iterator.

for/release
dmatetelki 11 years ago
parent e4b9b94e39
commit 3e28a3a7d5

@ -63,7 +63,7 @@ private:
void addEdge(v_iterator destination, const_weight_reference weight = weight_type()); void addEdge(v_iterator destination, const_weight_reference weight = weight_type());
void removeEdge(v_iterator destination, const_weight_reference weight = weight_type()); void removeEdge(v_iterator destination, const_weight_reference weight = weight_type());
void removeAllEdgesTo(v_iterator destination); void removeAllEdgesTo(v_iterator destination);
std::vector<Edge> edges(v_const_iterator this_it) const; std::vector<Edge> edges() const;
value_type m_data; value_type m_data;
std::list<EdgeTo> m_edges; std::list<EdgeTo> m_edges;
@ -76,14 +76,14 @@ public:
public: public:
Edge() : source(), destination(), weight() {} Edge() : source(), destination(), weight() {}
Edge(vertex_iterator source, vertex_iterator destination, const_weight_reference weight); Edge(const_reference source, const_reference destination, const_weight_reference weight);
Edge(const Edge& o); Edge(const Edge& o);
Edge& operator=(Edge o) { swap(o); return *this; } Edge& operator=(Edge o) { swap(o); return *this; }
void swap(Edge& o); void swap(Edge& o);
bool operator==(const Edge& o) const { return source == o.source && destination == o.destination && weight == o.weight; } bool operator==(const Edge& o) const { return source == o.source && destination == o.destination && weight == o.weight; }
vertex_iterator source; /// @todo shall it be value_type ? value_type source;
vertex_iterator destination; /// @todo shall it be value_type ? value_type destination;
weight_type weight; weight_type weight;
}; };
@ -213,7 +213,7 @@ private:
v_iterator find(const_reference data); v_iterator find(const_reference data);
void adjustEdges(v_iterator vit); void adjustEdges(v_iterator vit);
bool m_directed; const bool m_directed;
v_container m_vertices; v_container m_vertices;
}; };
@ -221,7 +221,7 @@ private:
// Edge // Edge
template <typename V, typename E> template <typename V, typename E>
inline Graph<V, E>::Edge::Edge(vertex_iterator s, vertex_iterator d, const_weight_reference w) inline Graph<V, E>::Edge::Edge(const_reference s, const_reference d, const_weight_reference w)
: source(s) : source(s)
, destination(d) , destination(d)
, weight(w) , weight(w)
@ -296,7 +296,7 @@ inline void Graph<V, E>::edge_iterator::resetEdge()
if (m_vertex_it == m_vertices.end() || (*m_vertex_it).m_edges.empty()) { if (m_vertex_it == m_vertices.end() || (*m_vertex_it).m_edges.empty()) {
m_edge = Edge(); m_edge = Edge();
} else { } else {
m_edge = Edge( m_vertex_it, (*m_edge_it).m_destination, (*m_edge_it).m_weight); m_edge = Edge( m_vertex_it->m_data, (m_edge_it->m_destination)->m_data, (*m_edge_it).m_weight);
} }
} }
@ -379,14 +379,14 @@ inline void Graph<V, E>::Vertex::removeAllEdgesTo(v_iterator destination)
} }
template <typename V, typename E> template <typename V, typename E>
inline std::vector<typename Graph<V, E>::Edge> Graph<V, E>::Vertex::edges(v_const_iterator this_it) const inline std::vector<typename Graph<V, E>::Edge> Graph<V, E>::Vertex::edges() const
{ {
std::vector<Graph<V, E>::Edge> retval; std::vector<Graph<V, E>::Edge> retval;
/// @todo rewrite for_each to parallel aware /// @todo rewrite for_each to parallel aware
std::for_each(m_edges.begin(), m_edges.end(), std::for_each(m_edges.begin(), m_edges.end(),
[&retval, this_it](const EdgeTo& e) [this, &retval](const EdgeTo& e)
{ retval.push_back(Edge(vertex_iterator(this_it), vertex_iterator(e.m_destination), e.m_weight)); }); { retval.push_back(Edge(m_data, (e.m_destination)->m_data, e.m_weight)); });
return retval; return retval;
} }
@ -532,11 +532,12 @@ inline std::vector<typename Graph<V, E>::Edge> Graph<V, E>::edges() const
{ {
std::vector<typename Graph<V, E>::Edge> retval; std::vector<typename Graph<V, E>::Edge> retval;
/// @todo rewrite use some STL alg with parallel in mind /// @todo rewrite for_each to parallel aware
for (v_const_iterator it = m_vertices.begin(); it != m_vertices.end(); ++it) { std::for_each(m_vertices.begin(), m_vertices.end(),
const std::vector<Edge> e = (*it).edges(it); [&retval](const Vertex& v)
{ const std::vector<Edge> e = v.edges();
retval.insert(retval.end(), e.begin(), e.end()); retval.insert(retval.end(), e.begin(), e.end());
} });
return retval; return retval;
} }

Loading…
Cancel
Save