From 4ae5213d9dcaa7fc39516f1a2ca74845049de51d Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Thu, 30 May 2024 17:07:37 +0200 Subject: [PATCH 1/3] Use custom struct instead of std::pair in QueryHeap --- include/util/query_heap.hpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/include/util/query_heap.hpp b/include/util/query_heap.hpp index c9f1fc6c55c..80eb100619c 100644 --- a/include/util/query_heap.hpp +++ b/include/util/query_heap.hpp @@ -193,7 +193,20 @@ template ; + struct HeapData + { + Weight weight; + Key index; + + bool operator>(const HeapData &other) const + { + if (weight == other.weight) + { + return index > other.index; + } + return weight > other.weight; + } + }; using HeapContainer = boost::heap::d_ary_heap, boost::heap::mutable_, @@ -232,7 +245,7 @@ class QueryHeap { BOOST_ASSERT(node < std::numeric_limits::max()); const auto index = static_cast(inserted_nodes.size()); - const auto handle = heap.push(std::make_pair(weight, index)); + const auto handle = heap.emplace(HeapData{weight, index}); inserted_nodes.emplace_back(HeapNode{handle, node, weight, data}); node_index[node] = index; } @@ -315,19 +328,19 @@ class QueryHeap NodeID Min() const { BOOST_ASSERT(!heap.empty()); - return inserted_nodes[heap.top().second].node; + return inserted_nodes[heap.top().index].node; } Weight MinKey() const { BOOST_ASSERT(!heap.empty()); - return heap.top().first; + return heap.top().weight; } NodeID DeleteMin() { BOOST_ASSERT(!heap.empty()); - const Key removedIndex = heap.top().second; + const Key removedIndex = heap.top().index; heap.pop(); inserted_nodes[removedIndex].handle = heap.s_handle_from_iterator(heap.end()); return inserted_nodes[removedIndex].node; @@ -336,7 +349,7 @@ class QueryHeap HeapNode &DeleteMinGetHeapNode() { BOOST_ASSERT(!heap.empty()); - const Key removedIndex = heap.top().second; + const Key removedIndex = heap.top().index; heap.pop(); inserted_nodes[removedIndex].handle = heap.s_handle_from_iterator(heap.end()); return inserted_nodes[removedIndex]; @@ -357,13 +370,13 @@ class QueryHeap const auto index = node_index.peek_index(node); auto &reference = inserted_nodes[index]; reference.weight = weight; - heap.increase(reference.handle, std::make_pair(weight, index)); + heap.increase(reference.handle, HeapData{weight, index}); } void DecreaseKey(const HeapNode &heapNode) { BOOST_ASSERT(!WasRemoved(heapNode.node)); - heap.increase(heapNode.handle, std::make_pair(heapNode.weight, (*heapNode.handle).second)); + heap.increase(heapNode.handle, HeapData{heapNode.weight, (*heapNode.handle).index}); } private: From 608f6ca383dc038e84071c2f59b9972f2ffa734f Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Thu, 30 May 2024 17:22:01 +0200 Subject: [PATCH 2/3] Use custom struct instead of std::pair in QueryHeap --- include/util/query_heap.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/util/query_heap.hpp b/include/util/query_heap.hpp index 80eb100619c..9ded36c9e86 100644 --- a/include/util/query_heap.hpp +++ b/include/util/query_heap.hpp @@ -370,7 +370,7 @@ class QueryHeap const auto index = node_index.peek_index(node); auto &reference = inserted_nodes[index]; reference.weight = weight; - heap.increase(reference.handle, HeapData{weight, index}); + heap.increase(reference.handle, HeapData{weight, static_cast(index)}); } void DecreaseKey(const HeapNode &heapNode) From 34070020a73e630af5fb3742bbbebeb43fafe310 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Thu, 30 May 2024 17:51:43 +0200 Subject: [PATCH 3/3] Use custom struct instead of std::pair in QueryHeap --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbeaf91df33..328c3895e19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - NodeJS: - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - Misc: + - CHANGED: Use custom struct instead of std::pair in QueryHeap. [#6921](https://github.com/Project-OSRM/osrm-backend/pull/6921) - CHANGED: Make constants in PackedVector constexpr. [#6917](https://github.com/Project-OSRM/osrm-backend/pull/6917) - CHANGED: Use std::variant instead of mapbox::util::variant. [#6903](https://github.com/Project-OSRM/osrm-backend/pull/6903) - CHANGED: Bump rapidjson to version f9d53419e912910fd8fa57d5705fa41425428c35 [#6906](https://github.com/Project-OSRM/osrm-backend/pull/6906)