| 8 | |
| 9 | // in its essence it is std::priority_queue, but with `clear` method |
| 10 | template <typename T> class BinaryHeap |
| 11 | { |
| 12 | public: |
| 13 | bool empty() const { return heap_.empty(); } |
| 14 | |
| 15 | const T &top() const |
| 16 | { |
| 17 | BOOST_ASSERT(!heap_.empty()); |
| 18 | return heap_.front(); |
| 19 | } |
| 20 | |
| 21 | void pop() |
| 22 | { |
| 23 | BOOST_ASSERT(!heap_.empty()); |
| 24 | std::pop_heap(heap_.begin(), heap_.end()); |
| 25 | heap_.pop_back(); |
| 26 | } |
| 27 | |
| 28 | template <typename... Args> void emplace(Args &&...args) |
| 29 | { |
| 30 | heap_.emplace_back(std::forward<Args>(args)...); |
| 31 | std::push_heap(heap_.begin(), heap_.end()); |
| 32 | } |
| 33 | |
| 34 | void clear() { heap_.clear(); } |
| 35 | |
| 36 | private: |
| 37 | std::vector<T> heap_; |
| 38 | }; |
| 39 | |
| 40 | } // namespace osrm::util |