|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
45 template<
typename,
typename>
70 template<
typename T,
typename C>
81 explicit PairingHeap(
const C& cmp = C(),
int initialSize = -1);
92 const T&
top()
const override;
154 template<
typename T,
typename C>
158 template<
typename T,
typename C>
164 template<
typename T,
typename C>
167 return m_root->value;
170 template<
typename T,
typename C>
174 m_root = m_root ==
nullptr ? heapNode : merge(m_root, heapNode);
178 template<
typename T,
typename C>
183 m_root = pair(children);
186 template<
typename T,
typename C>
188 heapNode->
value = value;
189 if (heapNode->
prev !=
nullptr) {
191 m_root = merge(m_root, heapNode);
195 template<
typename T,
typename C>
197 m_root = merge(m_root, other.
m_root);
201 template<
typename T,
typename C>
203 if (heapNode ==
nullptr) {
215 while (it->
next !=
nullptr) {
222 if (children % 2 == 1) {
230 a->
prev = a->
next = b->prev = b->next =
nullptr;
231 result = merge(a, b);
234 for (
size_t i = 0; i < (children - 1) / 2; i++) {
237 a->
prev = a->
next = b->prev = b->next =
nullptr;
238 result = merge(merge(a, b), result);
244 template<
typename T,
typename C>
261 template<
typename T,
typename C>
263 if (root->
child !=
nullptr) {
265 root->
child->prev = child;
271 template<
typename T,
typename C>
273 if (heapNode->
prev->child == heapNode) {
274 heapNode->
prev->child = heapNode->
next;
276 heapNode->
prev->next = heapNode->
next;
278 if (heapNode->
next !=
nullptr) {
279 heapNode->
next->prev = heapNode->
prev;
281 heapNode->
prev =
nullptr;
282 heapNode->
next =
nullptr;
285 template<
typename T,
typename C>
299 if (it->
child !=
nullptr) {
303 if (it->
next !=
nullptr) {
313 if (prev ==
nullptr) {
316 if (curr == prev->
child && prev->next !=
nullptr) {
void pop() override
Removes the top element from the heap.
The namespace for all OGDF objects.
Common interface for all heap classes.
PairingHeapNode< T > * child
First child of the node.
virtual ~PairingHeap()
Destructs pairing heap.
static void link(PairingHeapNode< T > *parent, PairingHeapNode< T > *child)
Makes child node a child of parent node.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
PairingHeapNode< T > * pair(PairingHeapNode< T > *heapNode)
Pairs list of heaps given as heapNode. Returns resulting list.
PairingHeap(const C &cmp=C(), int initialSize=-1)
Creates empty pairing heap.
void decrease(PairingHeapNode< T > *heapNode, const T &value) override
Decreases value of the given heapNode to value.
PairingHeapNode< T > * prev
Previous sibling of the node or parent.
void merge(PairingHeap< T, C > &other) override
Merges in values of other heap.
Pairing heap implementation.
const T & value(PairingHeapNode< T > *heapNode) const override
Returns the value of the node.
PairingHeapNode< T > * push(const T &value) override
Inserts a new node with given value into a heap.
Interface for heap implementations.
PairingHeapNode< T > * next
Next sibling of the node.
Basic declarations, included by all source files.
const T & top() const override
Returns reference to the top element in the heap.
PairingHeapNode(const T &valueOfNode)
Creates heap node with a given valueOfNode.
T value
Value contained in the node.
PairingHeapNode< T > * m_root
Root node of the heap.
static void unlink(PairingHeapNode< T > *heapNode)
Removes heapNode from its parent children list.
static void release(PairingHeapNode< T > *heapNode)
Releases memory occupied by list of heaps given as heapNode.