adding todos, for_each to access 1 reduct variable is not parallel wise

for/release
dmatetelki 11 years ago
parent e57077d305
commit 81239895ad

@ -191,11 +191,11 @@ private:
struct Vertex { struct Vertex {
Vertex(const_reference data) : m_data(data), m_edges() {} Vertex(const_reference data) : m_data(data), m_edges() {}
Vertex(const Vertex& o) : m_data(o.m_data), m_edges(o.m_edges) {} Vertex(const_reference o) : m_data(o.m_data), m_edges(o.m_edges) {}
Vertex& operator=(Vertex o) { swap(o); return *this; } Vertex& operator=(Vertex o) { swap(o); return *this; }
void swap(Vertex& o) { std::swap(m_data, o.m_data); std::swap(m_edges, o.m_edges);} void swap(Vertex& o) { std::swap(m_data, o.m_data); std::swap(m_edges, o.m_edges);}
bool operator==(const Vertex& other) const; bool operator==(const_reference other) const;
void addEdge(const_pointer destination, const_weight_reference weight = weight_type()); void addEdge(const_pointer destination, const_weight_reference weight = weight_type());
void removeEdge(const_reference destination, const_weight_reference weight = weight_type()); void removeEdge(const_reference destination, const_weight_reference weight = weight_type());
@ -342,7 +342,7 @@ inline bool Graph<V, E>::EdgeTo::operator==(const EdgeTo& other) const
// Vertex // Vertex
template <typename V, typename E> template <typename V, typename E>
inline bool Graph<V, E>::Vertex::operator==(const Vertex& other) const inline bool Graph<V, E>::Vertex::operator==(const_reference other) const
{ {
return m_data == other.m_data && return m_data == other.m_data &&
m_edges.size() == other.m_edges.size() && m_edges.size() == other.m_edges.size() &&
@ -376,6 +376,7 @@ template <typename V, typename E>
inline std::vector<typename Graph<V, E>::Edge> Graph<V, E>::Vertex::edges() 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
std::for_each(m_edges.begin(), m_edges.end(), std::for_each(m_edges.begin(), m_edges.end(),
[&retval, this](const EdgeTo& e) [&retval, this](const EdgeTo& e)
{ retval.push_back(Edge( &this->m_data, e.m_destination, e.m_weight)); }); { retval.push_back(Edge( &this->m_data, e.m_destination, e.m_weight)); });
@ -400,7 +401,7 @@ inline typename Graph<V, E>::size_type Graph<V, E>::numberOfEdges() const
/// @bug does not work with parallel mode /// @bug does not work with parallel mode
return std::accumulate(m_vertices.begin(), m_vertices.end(), 0, return std::accumulate(m_vertices.begin(), m_vertices.end(), 0,
[](int sum, const Vertex& v) [](int sum, const_reference v)
{ return sum + v.m_edges.size(); }); { return sum + v.m_edges.size(); });
#endif #endif
} }
@ -489,8 +490,9 @@ template <typename V, typename E>
inline std::vector<typename Graph<V, E>::value_type> Graph<V, E>::vertices() const inline std::vector<typename Graph<V, E>::value_type> Graph<V, E>::vertices() const
{ {
std::vector<value_type> retval; std::vector<value_type> retval;
/// @todo rewrite for_each to parallel aware
std::for_each(m_vertices.begin(), m_vertices.end(), std::for_each(m_vertices.begin(), m_vertices.end(),
[&retval](const Vertex& v) [&retval](const_reference v)
{ retval.push_back(v.m_data); }); { retval.push_back(v.m_data); });
return retval; return retval;
} }
@ -504,6 +506,7 @@ std::vector<typename Graph<V, E>::value_type> Graph<V, E>::neighboursOf(const_re
return retval; return retval;
std::set<value_type> tmp; std::set<value_type> tmp;
/// @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)
{ if (tmp.insert(*e.m_destination).second) { if (tmp.insert(*e.m_destination).second)
@ -520,6 +523,7 @@ std::vector<E> Graph<V, E>::weightsBetween(const_reference source, const_referen
if (vertex_it == m_vertices.end()) if (vertex_it == m_vertices.end())
return retval; return retval;
/// @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(),
[&retval, &destination](const EdgeTo& e) [&retval, &destination](const EdgeTo& e)
{ if (*(e.m_destination) == destination) { if (*(e.m_destination) == destination)
@ -533,8 +537,9 @@ 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 for_each to parallel aware
std::for_each(m_vertices.begin(), m_vertices.end(), std::for_each(m_vertices.begin(), m_vertices.end(),
[&retval](const Vertex& v) [&retval](const_reference v)
{ const std::vector<Edge> e = v.edges(); { const std::vector<Edge> e = v.edges();
retval.insert(retval.end(), e.begin(), e.end()); retval.insert(retval.end(), e.begin(), e.end());
}); });
@ -548,7 +553,7 @@ inline typename std::vector<typename Graph<V, E>::Vertex >::const_iterator
Graph<V, E>::find(const_reference data) const Graph<V, E>::find(const_reference data) const
{ {
return std::find_if(m_vertices.begin(), m_vertices.end(), return std::find_if(m_vertices.begin(), m_vertices.end(),
[&data](const Vertex& v) [&data](const_reference v)
{ return v.m_data == data; }); { return v.m_data == data; });
} }
@ -558,7 +563,7 @@ inline typename std::vector<typename Graph<V, E>::Vertex >::iterator
Graph<V, E>::find(const_reference data) Graph<V, E>::find(const_reference data)
{ {
return std::find_if(m_vertices.begin(), m_vertices.end(), return std::find_if(m_vertices.begin(), m_vertices.end(),
[&data](const Vertex& v) [&data](const_reference v)
{ return v.m_data == data; }); { return v.m_data == data; });
} }

Loading…
Cancel
Save