45 template<
typename V,
typename P>
54 : prev(nullptr), next(nullptr)
59 : value(val), priority(pr),
60 prev(nullptr), next(nullptr)
75 template<
typename V,
typename P,
typename HeapHandle>
92 : type(
Type::heap), heapHandle(handle)
98 : type(
Type::bucket), bucketHandle(index, queueNode)
117 typename V1,
typename P1,
template<
typename T,
typename C>
class H1
135 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
156 HotQueue(
const P &change, std::size_t levels);
162 const V &top()
const;
202 bool operator()(
const std::pair<V, P> &a,
const std::pair<V, P> &b)
const {
203 return std::get<1>(a) < std::get<1>(b);
214 return (std::size_t) std::round(priority / m_bucketSpan);
219 return m_buckets[index % m_buckets.size()];
222 static constexpr std::size_t NONE = std::numeric_limits<size_t>::max();
226 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
228 : m_size(0), m_heapSize(0),
229 m_buckets(levels, nullptr),
230 m_heapedBucket(NONE), m_lastBucket(0),
231 m_bucketSpan((int) std::round(change / (levels - 1)))
235 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
242 if (bucket !=
nullptr) {
252 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
255 return std::get<0>(
m_heap.top());
259 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
261 const V &value,
const P &priority)
285 return Handle(ind, queueNode);
290 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
316 m_heap.push(std::make_pair(it->value, it->priority));
326 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
331 switch(handle.
type) {
335 m_heap.decrease(elem, std::make_pair(
336 std::get<0>(
m_heap.value(elem)), priority)
343 if(queueNode->
next !=
nullptr) {
344 queueNode->
next->prev = queueNode->
prev;
346 if(queueNode->
prev !=
nullptr) {
347 queueNode->
prev->next = queueNode->
next;
354 handle =
push(queueNode->
value, priority);
Heap-on-Top handle to inserted items.
enum ogdf::HotQueueHandle::Type type
Union tag.
HotQueueNode< V, P > * next
std::size_t m_heapedBucket
Index of currently heaped bucket.
H< std::pair< V, P >, HeapComparator > m_heap
Underlying heap structure.
HotQueueHandle< V, P, HeapHandle > Handle
void pop()
Removes the top element from the heap.
std::size_t m_size
Number of total elements in the heap.
static constexpr std::size_t NONE
bool operator()(const std::pair< V, P > &a, const std::pair< V, P > &b) const
HotQueueHandle & operator=(const HotQueueHandle &other)
typename H< std::pair< V, P >, HeapComparator >::Handle HeapHandle
Handle push(const V &value, const P &priority)
Inserts a new node with given value and priority into a heap.
std::size_t bucketIndex(const P &priority)
Computes bucket index of given priority.
HotQueue(const P &change, std::size_t levels)
Creates empty Heap-on-Top queue.
HotQueueHandle(HeapHandle handle)
Creates heap-type handle.
void decrease(Handle &handle, const P &priority)
Decreases value of the given handle to priority.
HotQueueHandle(std::size_t index, HotQueueNode< V, P > *queueNode)
Creates bucket-type handle.
std::size_t m_lastBucket
Index of highest, non-empty bucket.
const P m_bucketSpan
Length of the interval covered by each bucket.
HeapHandle heapHandle
Handle to underlying heap.
HotQueueNode< V, P > *& bucketAt(std::size_t index)
Provides access to bucket at given index.
std::vector< HotQueueNode< V, P > * > m_buckets
Array of buckets.
HotQueueNode(const V &val, const P &pr)
std::size_t size() const
Number of elements contained within the heap.
~HotQueue()
Releases all buckets on destruction.
std::pair< std::size_t, HotQueueNode< V, P > * > bucketHandle
Handle to bucket element (bucket index and list iterator).
Heap-on-Top queue implementation.
const V & top() const
Returns reference to the top element in the heap.
std::size_t m_heapSize
Size of underlying heap.
The namespace for all OGDF objects.
HotQueueNode< V, P > * prev
Heap-on-Top bucket element.
bool empty() const
Checks whether the heap is empty.
Comparator used by underlying heap.