Skip to content

Commit

Permalink
CHG: [C++] maintain min-heap property between calls
Browse files Browse the repository at this point in the history
Suggest change by Tomasz W.
  • Loading branch information
RUrlus committed Feb 1, 2024
1 parent abf0192 commit 9075ff5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/sparse_dot_topn_core/include/sparse_dot_topn/maxheap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 9075ff5

Please sign in to comment.