Skip to content

num::indexed_priority_queue

Defined in header <structures/containers/indexed_priority_queue.hpp>

template <typename Key = double, std::integral Index = num::idx,
          typename Compare = std::less<Key>>
class indexed_priority_queue;

Addressable priority queue where each item is identified by a unique index in [0, capacity).

Template parameters

  • Key: The priority key type (e.g. double, float, int).
  • Index: The integer type for element indices (e.g. num::idx, uint32_t).
  • Compare: Comparator where comp(a, b) == true means a has higher priority (default std::less for min-heap).

Members

member description
using key_type = Key
using index_type = Index
using compare_type = Compare
explicit indexed_priority_queue(Index capacity = 0, Compare comp = Compare{}) Construct an indexed priority queue for indices up to capacity.
void push(Index index, const Key &key) Insert index with associated priority key.
void pop() Remove the top (highest-priority) element from the queue.
Index top_index() const Return the index of the highest-priority element.
const Key &top_key() const Return the key of the highest-priority element.
bool contains(Index index) const noexcept Check if index is currently present in the priority queue.
const Key &key_of(Index index) const Return the key associated with element index.
void update(Index index, const Key &new_key) Update the key of element index (re-heaps up or down as needed).
void improve_key(Index index, const Key &new_key) Decrease/increase key with priority improvement.
void erase(Index index) Erase element index from the priority queue.
bool empty() const noexcept Check whether the priority queue is empty.
Index size() const noexcept Return the number of elements in the priority queue.
Index capacity() const noexcept Return maximum index capacity.
void clear() noexcept Clear all elements.