From 64e8db157d766030853d8ea7e386be517082d1a6 Mon Sep 17 00:00:00 2001 From: dmatetelki Date: Thu, 27 Aug 2015 12:14:30 +0200 Subject: [PATCH] PriorityQueue does not have contains fn anymore --- lib/graph/priority_queue.hpp | 18 ++++++++---------- test/graph/test_priority_queue.cpp | 8 ++------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/graph/priority_queue.hpp b/lib/graph/priority_queue.hpp index 996f9ff..ae6496b 100644 --- a/lib/graph/priority_queue.hpp +++ b/lib/graph/priority_queue.hpp @@ -28,25 +28,23 @@ public: PriorityQueue() : m_map() {} // capacity - size_t size() const { return m_map.size(); } - bool empty() const { return m_map.empty(); } + size_t size() const noexcept { return m_map.size(); } + bool empty() const noexcept { return m_map.empty(); } // lookup - std::pair top() const { return *m_map.begin(); } + std::pair top() const noexcept { return *m_map.begin(); } // modifiers void pop() { m_map.erase(m_map.begin()); } void push(const Key& key, const T& value) { m_map.emplace(key, value); } - void modifyKey(const Key& key, const T& value, const Key& new_key) { - auto it = std::find_if(m_map.begin(), m_map.end(), [&key, &value](const std::pair & p) { return p.first == key && p.second == value; } ); + bool modifyKey(const Key& key, const T& value, const Key& new_key) { + auto it = std::find_if(m_map.begin(), m_map.end(), + [&key, &value](const std::pair & p) { return p.first == key && p.second == value; } ); + if (it == m_map.end()) return false; T v = it->second; // take a copy m_map.erase(it); m_map.emplace(new_key, v); - } - - bool contains(const T& value) const { - auto it = std::find_if(m_map.begin(), m_map.end(), [&value](const std::pair & p) { return p.second == value; } ); - return it != m_map.end(); + return true; } private: diff --git a/test/graph/test_priority_queue.cpp b/test/graph/test_priority_queue.cpp index 9e0c408..2ebbd56 100644 --- a/test/graph/test_priority_queue.cpp +++ b/test/graph/test_priority_queue.cpp @@ -26,7 +26,6 @@ typedef std::pair P; REQUIRE( pq.size() == 1 ); REQUIRE( pq.empty() == false ); - REQUIRE( pq.contains(f2) == true ); P p = pq.top(); REQUIRE( p.second == f2 ); @@ -48,9 +47,6 @@ typedef std::pair P; REQUIRE( pq.size() == 3 ); REQUIRE( pq.empty() == false ); - REQUIRE( pq.contains(f2_1) == true ); - REQUIRE( pq.contains(f2_2) == true ); - REQUIRE( pq.contains(f2_3) == true ); P p1 = pq.top(); pq.pop(); @@ -83,8 +79,8 @@ typedef std::pair P; pq.push(1.0f, f2_1); pq.push(2.0f, f2_2); - pq.modifyKey(f2_1, +3.0f); - pq.modifyKey(f2_3, -2.0f); + pq.modifyKey(1.0f, f2_1, 1.0f + 3.0f); + pq.modifyKey(3.0f, f2_3, 3.0f - 2.0f); P p1 = pq.top(); pq.pop();