From 9075ff5876596870822fec17ff8f2a4828ac662c Mon Sep 17 00:00:00 2001 From: Ralph Urlus Date: Thu, 1 Feb 2024 13:12:38 +0100 Subject: [PATCH] CHG: [C++] maintain min-heap property between calls Suggest change by Tomasz W. --- src/sparse_dot_topn_core/include/sparse_dot_topn/maxheap.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sparse_dot_topn_core/include/sparse_dot_topn/maxheap.hpp b/src/sparse_dot_topn_core/include/sparse_dot_topn/maxheap.hpp index fc28f82..ec1361b 100644 --- a/src/sparse_dot_topn_core/include/sparse_dot_topn/maxheap.hpp +++ b/src/sparse_dot_topn_core/include/sparse_dot_topn/maxheap.hpp @@ -86,13 +86,13 @@ class MaxHeap { * \param val value to store */ eT push_pop(const idxT idx, const eT val) { + std::pop_heap(heap.begin(), heap.end(), compare()); heap.back().order = n_set; heap.back().idx = idx; heap.back().val = val; n_set++; std::push_heap(heap.begin(), heap.end(), compare()); - std::pop_heap(heap.begin(), heap.end(), compare()); - return heap.back().val; + return heap.front().val; } /**