From 81239895ad2a5bf5ffce9496ac16d577c22232a7 Mon Sep 17 00:00:00 2001 From: dmatetelki Date: Fri, 9 May 2014 14:08:39 +0200 Subject: [PATCH] adding todos, for_each to access 1 reduct variable is not parallel wise --- lib/graph/graph.hpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/graph/graph.hpp b/lib/graph/graph.hpp index 81164a1..3b316e0 100644 --- a/lib/graph/graph.hpp +++ b/lib/graph/graph.hpp @@ -191,11 +191,11 @@ private: struct Vertex { 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; } 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 removeEdge(const_reference destination, const_weight_reference weight = weight_type()); @@ -342,7 +342,7 @@ inline bool Graph::EdgeTo::operator==(const EdgeTo& other) const // Vertex template -inline bool Graph::Vertex::operator==(const Vertex& other) const +inline bool Graph::Vertex::operator==(const_reference other) const { return m_data == other.m_data && m_edges.size() == other.m_edges.size() && @@ -376,6 +376,7 @@ template inline std::vector::Edge> Graph::Vertex::edges() const { std::vector::Edge> retval; + /// @todo rewrite for_each to parallel aware std::for_each(m_edges.begin(), m_edges.end(), [&retval, this](const EdgeTo& e) { retval.push_back(Edge( &this->m_data, e.m_destination, e.m_weight)); }); @@ -400,7 +401,7 @@ inline typename Graph::size_type Graph::numberOfEdges() const /// @bug does not work with parallel mode 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(); }); #endif } @@ -489,8 +490,9 @@ template inline std::vector::value_type> Graph::vertices() const { std::vector retval; + /// @todo rewrite for_each to parallel aware std::for_each(m_vertices.begin(), m_vertices.end(), - [&retval](const Vertex& v) + [&retval](const_reference v) { retval.push_back(v.m_data); }); return retval; } @@ -504,6 +506,7 @@ std::vector::value_type> Graph::neighboursOf(const_re return retval; 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) { if (tmp.insert(*e.m_destination).second) @@ -520,6 +523,7 @@ std::vector Graph::weightsBetween(const_reference source, const_referen if (vertex_it == m_vertices.end()) return retval; + /// @todo rewrite for_each to parallel aware std::for_each((*vertex_it).m_edges.begin(), (*vertex_it).m_edges.end(), [&retval, &destination](const EdgeTo& e) { if (*(e.m_destination) == destination) @@ -533,8 +537,9 @@ inline std::vector::Edge> Graph::edges() const { std::vector::Edge> retval; + /// @todo rewrite for_each to parallel aware std::for_each(m_vertices.begin(), m_vertices.end(), - [&retval](const Vertex& v) + [&retval](const_reference v) { const std::vector e = v.edges(); retval.insert(retval.end(), e.begin(), e.end()); }); @@ -548,7 +553,7 @@ inline typename std::vector::Vertex >::const_iterator Graph::find(const_reference data) const { return std::find_if(m_vertices.begin(), m_vertices.end(), - [&data](const Vertex& v) + [&data](const_reference v) { return v.m_data == data; }); } @@ -558,7 +563,7 @@ inline typename std::vector::Vertex >::iterator Graph::find(const_reference data) { return std::find_if(m_vertices.begin(), m_vertices.end(), - [&data](const Vertex& v) + [&data](const_reference v) { return v.m_data == data; }); }