44template<
typename V,
typename P>
67template<
typename V,
typename P,
typename HeapHandle>
103 template<
typename V1,
typename P1,
template<
typename T,
typename C>
class H1>
119template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
146 const V&
top()
const;
182 bool operator()(
const std::pair<V, P>& a,
const std::pair<V, P>& b)
const {
183 return std::get<1>(a) < std::get<1>(b);
194 return (std::size_t)std::round(priority /
m_bucketSpan);
200 static constexpr std::size_t
NONE = std::numeric_limits<size_t>::max();
203template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
208 , m_heapedBucket(NONE)
212template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
217 for (
auto& bucket : m_buckets) {
218 if (bucket !=
nullptr) {
228template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
230 return std::get<0>(m_heap.top());
233template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
237 std::size_t
ind = bucketIndex(priority);
239 if (m_heapedBucket == NONE) {
240 m_heapedBucket =
ind;
243 if (
ind == m_heapedBucket) {
245 HeapHandle handle = m_heap.push(std::make_pair(value, priority));
250 if (bucketAt(
ind) !=
nullptr) {
256 m_lastBucket = std::max(m_lastBucket,
ind);
261template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
274 if (!(m_heapSize == 0 && m_heapedBucket != m_lastBucket)) {
281 }
while (bucketAt(m_heapedBucket) ==
nullptr);
286 m_heap.push(std::make_pair(it->value, it->priority));
292 bucketAt(m_heapedBucket) =
nullptr;
295template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
297 switch (handle.
type) {
298 case Handle::Type::heap: {
301 m_heap.decrease(
elem, std::make_pair(std::get<0>(m_heap.value(
elem)), priority));
304 case Handle::Type::bucket:
318 handle = push(
queueNode->value, priority);
Heap-on-Top queue implementation.
std::size_t bucketIndex(const P &priority)
Computes bucket index of given priority.
std::size_t m_lastBucket
Index of highest, non-empty bucket.
static constexpr std::size_t NONE
HotQueueNode< V, P > *& bucketAt(std::size_t index)
Provides access to bucket at given index.
bool empty() const
Checks whether the heap is empty.
H< std::pair< V, P >, HeapComparator > m_heap
Underlying heap structure.
HotQueue(const P &change, std::size_t levels)
Creates empty Heap-on-Top queue.
typename H< std::pair< V, P >, HeapComparator >::Handle HeapHandle
~HotQueue()
Releases all buckets on destruction.
std::size_t m_heapedBucket
Index of currently heaped bucket.
const P m_bucketSpan
Length of the interval covered by each bucket.
const V & top() const
Returns reference to the top element in the heap.
std::size_t m_heapSize
Size of underlying heap.
void pop()
Removes the top element from the heap.
std::vector< HotQueueNode< V, P > * > m_buckets
Array of buckets.
void decrease(Handle &handle, const P &priority)
Decreases value of the given handle to priority.
Handle push(const V &value, const P &priority)
Inserts a new node with given value and priority into a heap.
std::size_t m_size
Number of total elements in the heap.
HotQueueHandle< V, P, HeapHandle > Handle
std::size_t size() const
Number of elements contained within the heap.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Comparator used by underlying heap.
bool operator()(const std::pair< V, P > &a, const std::pair< V, P > &b) const
Heap-on-Top handle to inserted items.
std::pair< std::size_t, HotQueueNode< V, P > * > bucketHandle
Handle to bucket element (bucket index and list iterator).
HeapHandle heapHandle
Handle to underlying heap.
HotQueueHandle & operator=(const HotQueueHandle &other)
HotQueueHandle(const HotQueueHandle &other)
HotQueueHandle(HeapHandle handle)
Creates heap-type handle.
HotQueueHandle(std::size_t index, HotQueueNode< V, P > *queueNode)
Creates bucket-type handle.
enum ogdf::HotQueueHandle::Type type
Union tag.
Heap-on-Top bucket element.
HotQueueNode< V, P > * prev
HotQueueNode< V, P > * next
HotQueueNode(const V &val, const P &pr)