|
| | IndexedHeap (std::size_t capacity) |
| | Construct an empty heap capable of handles in [0, capacity).
|
| void | push (Idx handle, Key key, Val val) |
| | Insert an entry for handle.
|
| bool | contains (Idx handle) const noexcept |
| | Whether handle is currently present in the heap.
|
| void | decreaseKey (Idx handle, Key newKey) noexcept |
| | Lower the key of handle's entry to newKey.
|
| const Entry & | top () const noexcept |
| | Smallest-key entry currently in the heap.
|
| Entry | pop () noexcept |
| | Remove and return the smallest-key entry.
|
| std::size_t | size () const noexcept |
| | Current number of entries.
|
| bool | empty () const noexcept |
| | Whether the heap holds zero entries.
|
| std::size_t | capacity () const noexcept |
| | Maximum handle + 1 (the capacity passed at construction).
|
template<class Key, class Val, class Idx = std::uint32_t>
class clustering::IndexedHeap< Key, Val, Idx >
Binary min-heap keyed on Key with O(1) handle-to-position lookup.
Each heap entry carries an external Idx handle drawn from a fixed range [0, capacity). At most one entry per handle is in the heap at any time; the handle is cleared on pop and on construction. decreaseKey looks up the handle's position through m_posMap and sifts up; O(log n) worst case. Backed by heap-allocated vectors; allocation is constrained to construction and the occasional m_heap growth, never inside push / pop / decreaseKey.
- Template Parameters
-
| Key | Orderable key type; smaller keys pop first. |
| Val | Payload carried alongside the key. |
| Idx | Unsigned integer handle type; defaults to uint32_t. Handles index into a capacity-sized position map. |
Definition at line 109 of file heap.h.
template<class Key, class Val, class Idx = std::uint32_t>
Construct an empty heap capable of handles in [0, capacity).
Allocates the position map to capacity entries filled with kNotInHeap.
- Parameters
-
Definition at line 137 of file heap.h.
template<class Key, class Val, class Idx = std::uint32_t>
Lower the key of handle's entry to newKey.
Asserts handle is present and newKey is not greater than the current key (the classic decreaseKey precondition – raising a key would require sifting down, a different path). Sifts up from the handle's position; O(log n).
- Parameters
-
| handle | Handle of the entry to update. |
| newKey | Replacement key; must satisfy newKey <= current key. |
Definition at line 181 of file heap.h.
template<class Key, class Val, class Idx = std::uint32_t>
Insert an entry for handle.
Asserts handle is in range and not already present. Sifts up to restore the heap invariant; O(log n).
- Parameters
-
| handle | External identity of the entry; must be less than capacity. |
| key | Ordering key. |
| val | Payload. |
Definition at line 149 of file heap.h.