From 60648866a586793c724914e2c0d974f342ddb10a Mon Sep 17 00:00:00 2001 From: dmatetelki Date: Fri, 9 May 2014 13:57:56 +0200 Subject: [PATCH] E -> const E& --- lib/graph/graph.hpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/graph/graph.hpp b/lib/graph/graph.hpp index 2a63ae8..b2046cc 100644 --- a/lib/graph/graph.hpp +++ b/lib/graph/graph.hpp @@ -66,13 +66,12 @@ public: bool empty() const { return m_vertices.empty(); } size_type numberOfVertices() const { return m_vertices.size(); } size_type numberOfEdges() const; - void resize(size_type size) { m_vertices.resize(size); } // Modifiers bool addVertex(const_reference data); bool removeVertex(const_reference data); - bool addEdge(const_reference source, const_reference destination, E weight = 0); - bool removeEdge(const_reference source, const_reference destination, E weight = 0); + bool addEdge(const_reference source, const_reference destination, const E& weight = E()); + bool removeEdge(const_reference source, const_reference destination, const E& weight = E()); bool removeAllEdges(const_reference source, const_reference destination); // Lookup @@ -117,7 +116,6 @@ public: vertex_iterator(typename std::vector::iterator it) : m_it(it) {} vertex_iterator(typename std::vector::const_iterator it) : m_it(it) {} -// typename std::vector::const_iterator m_it; typename std::vector::iterator m_it; }; @@ -176,7 +174,7 @@ private: struct EdgeTo { - EdgeTo(const_pointer destination, E weight = E()); + EdgeTo(const_pointer destination, const E& weight = E()); EdgeTo(const EdgeTo& o) : m_destination(o.m_destination), m_weight(o.m_weight) {} EdgeTo& operator=(EdgeTo o) { swap(o); return *this; } void swap(EdgeTo& o); @@ -196,8 +194,8 @@ private: bool operator==(const Vertex& other) const; - void addEdge(const_pointer destination, E weight = E()); - void removeEdge(const_reference destination, E weight = E()); + void addEdge(const_pointer destination, const E& weight = E()); + void removeEdge(const_reference destination, const E& weight = E()); void removeAllEdgesTo(const_reference destination); std::vector edges() const; @@ -318,7 +316,7 @@ void Graph::edge_iterator::advance(int n) // EdgeTo template -inline Graph::EdgeTo::EdgeTo(const_pointer destination, E weight) +inline Graph::EdgeTo::EdgeTo(const_pointer destination, const E& weight) : m_destination(const_cast(destination)) , m_weight(weight) {} @@ -349,13 +347,13 @@ inline bool Graph::Vertex::operator==(const Vertex& other) const } template -inline void Graph::Vertex::addEdge(const_pointer destination, E weight) +inline void Graph::Vertex::addEdge(const_pointer destination, const E& weight) { m_edges.push_back(EdgeTo(destination, weight)); } template -inline void Graph::Vertex::removeEdge(const_reference destination, E weight) +inline void Graph::Vertex::removeEdge(const_reference destination, const E& weight) { m_edges.erase(std::find_if(m_edges.begin(), m_edges.end(), [&destination, &weight](const EdgeTo& e) @@ -375,14 +373,9 @@ template inline std::vector::Edge> Graph::Vertex::edges() const { std::vector::Edge> retval; -#ifdef _GLIBCXX_PARALLEL - for (auto& e : m_edges) - retval.push_back(Edge( &m_data, e.m_destination, e.m_weight)); -#else 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)); }); -#endif return retval; } @@ -436,7 +429,7 @@ inline bool Graph::removeVertex(const_reference data) } template -bool Graph::addEdge(const_reference source, const_reference destination, E weight) +bool Graph::addEdge(const_reference source, const_reference destination, const E& weight) { typename std::vector::iterator source_it = find(source); if (source_it == m_vertices.end()) @@ -454,7 +447,7 @@ bool Graph::addEdge(const_reference source, const_reference destination, E } template -inline bool Graph::removeEdge(const_reference source, const_reference destination, E weight) +inline bool Graph::removeEdge(const_reference source, const_reference destination, const E& weight) { typename std::vector::iterator source_it = find(source); if (source_it == m_vertices.end())