|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
46 template<
typename V,
typename P>
69 template<
typename V,
typename P,
typename HeapHandle>
105 template<
typename V1,
typename P1,
template<
typename T,
typename C>
class H1>
121 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
143 HotQueue(
const P& change, std::size_t levels);
149 const V&
top()
const;
157 Handle push(
const V& value,
const P& priority);
185 bool operator()(
const std::pair<V, P>& a,
const std::pair<V, P>& b)
const {
186 return std::get<1>(a) < std::get<1>(b);
197 return (std::size_t)std::round(priority /
m_bucketSpan);
203 static constexpr std::size_t
NONE = std::numeric_limits<size_t>::max();
206 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
210 , m_buckets(levels, nullptr)
211 , m_heapedBucket(NONE)
213 , m_bucketSpan((int)
std::round(change / (levels - 1))) { }
215 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
220 for (
auto& bucket : m_buckets) {
221 if (bucket !=
nullptr) {
231 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
233 return std::get<0>(m_heap.top());
236 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
240 std::size_t ind = bucketIndex(priority);
242 if (m_heapedBucket == NONE) {
243 m_heapedBucket = ind;
246 if (ind == m_heapedBucket) {
248 HeapHandle handle = m_heap.push(std::make_pair(value, priority));
253 if (bucketAt(ind) !=
nullptr) {
254 bucketAt(ind)->prev = queueNode;
256 queueNode->
next = bucketAt(ind);
257 bucketAt(ind) = queueNode;
259 m_lastBucket = std::max(m_lastBucket, ind);
260 return Handle(ind, queueNode);
264 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
277 if (!(m_heapSize == 0 && m_heapedBucket != m_lastBucket)) {
284 }
while (bucketAt(m_heapedBucket) ==
nullptr);
289 m_heap.push(std::make_pair(it->value, it->priority));
295 bucketAt(m_heapedBucket) =
nullptr;
298 template<
typename V,
typename P,
template<
typename T,
typename C>
class H>
300 switch (handle.
type) {
301 case Handle::Type::heap: {
304 m_heap.decrease(elem, std::make_pair(std::get<0>(m_heap.value(elem)), priority));
307 case Handle::Type::bucket:
310 if (queueNode->
next !=
nullptr) {
311 queueNode->
next->prev = queueNode->
prev;
313 if (queueNode->
prev !=
nullptr) {
314 queueNode->
prev->next = queueNode->
next;
321 handle = push(queueNode->
value, priority);
The namespace for all OGDF objects.
typename H< std::pair< V, P >, HeapComparator >::Handle HeapHandle
enum ogdf::HotQueueHandle::Type type
Union tag.
Comparator used by underlying heap.
HotQueueNode< V, P > *& bucketAt(std::size_t index)
Provides access to bucket at given index.
Heap-on-Top bucket element.
std::size_t m_lastBucket
Index of highest, non-empty bucket.
std::size_t size() const
Number of elements contained within the heap.
Handle push(const V &value, const P &priority)
Inserts a new node with given value and priority into a heap.
~HotQueue()
Releases all buckets on destruction.
const P m_bucketSpan
Length of the interval covered by each bucket.
Heap-on-Top handle to inserted items.
bool empty() const
Checks whether the heap is empty.
std::pair< std::size_t, HotQueueNode< V, P > * > bucketHandle
Handle to bucket element (bucket index and list iterator).
HotQueueHandle(const HotQueueHandle &other)
H< std::pair< V, P >, HeapComparator > m_heap
Underlying heap structure.
HotQueueHandle & operator=(const HotQueueHandle &other)
HotQueue(const P &change, std::size_t levels)
Creates empty Heap-on-Top queue.
std::size_t bucketIndex(const P &priority)
Computes bucket index of given priority.
HotQueueNode< V, P > * next
const V & top() const
Returns reference to the top element in the heap.
std::size_t m_heapSize
Size of underlying heap.
HeapHandle heapHandle
Handle to underlying heap.
HotQueueHandle< V, P, HeapHandle > Handle
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.
HotQueueNode< V, P > * prev
HotQueueHandle(std::size_t index, HotQueueNode< V, P > *queueNode)
Creates bucket-type handle.
HotQueueNode(const V &val, const P &pr)
Heap-on-Top queue implementation.
HotQueueHandle(HeapHandle handle)
Creates heap-type handle.
std::size_t m_size
Number of total elements in the heap.
static constexpr std::size_t NONE
void pop()
Removes the top element from the heap.
std::size_t m_heapedBucket
Index of currently heaped bucket.
bool operator()(const std::pair< V, P > &a, const std::pair< V, P > &b) const