Pairing heap implementation. More...
#include <ogdf/basic/heap/PairingHeap.h>
Public Member Functions | |
PairingHeap (const C &cmp=C(), int initialSize=-1) | |
Creates empty pairing heap. | |
virtual | ~PairingHeap () |
Destructs pairing heap. | |
void | decrease (PairingHeapNode< T > *heapNode, const T &value) override |
Decreases value of the given heapNode to value . | |
void | merge (PairingHeap< T, C > &other) override |
Merges in values of other heap. | |
void | pop () override |
Removes the top element from the heap. | |
PairingHeapNode< T > * | push (const T &value) override |
Inserts a new node with given value into a heap. | |
const T & | top () const override |
Returns reference to the top element in the heap. | |
const T & | value (PairingHeapNode< T > *heapNode) const override |
Returns the value of the node. | |
Public Member Functions inherited from ogdf::HeapBase< PairingHeap< T, C >, PairingHeapNode< T >, T, C > | |
HeapBase (const C &comp=C()) | |
virtual const C & | comparator () const |
Returns the comparator used to sort the values in the heap. | |
virtual void | decrease (Handle handle, const T &value)=0 |
Decreases a single value. | |
virtual void | merge (PairingHeap< T, C > &other) |
Merges in values of other heap. | |
virtual const T & | value (const Handle handle) const=0 |
Returns the value of that handle. | |
Private Types | |
using | base_type = HeapBase< PairingHeap< T, C >, PairingHeapNode< T >, T, C > |
Private Member Functions | |
PairingHeapNode< T > * | merge (PairingHeapNode< T > *a, PairingHeapNode< T > *b) |
Merges lists of heaps a and b . Returns resulting list. | |
PairingHeapNode< T > * | pair (PairingHeapNode< T > *heapNode) |
Pairs list of heaps given as heapNode . Returns resulting list. | |
Static Private Member Functions | |
static void | link (PairingHeapNode< T > *parent, PairingHeapNode< T > *child) |
Makes child node a child of parent node. | |
static void | release (PairingHeapNode< T > *heapNode) |
Releases memory occupied by list of heaps given as heapNode . | |
static void | unlink (PairingHeapNode< T > *heapNode) |
Removes heapNode from its parent children list. | |
Private Attributes | |
PairingHeapNode< T > * | m_root |
Root node of the heap. | |
Additional Inherited Members | |
Public Types inherited from ogdf::HeapBase< PairingHeap< T, C >, PairingHeapNode< T >, T, C > | |
using | Handle = PairingHeapNode< T > * |
The type of handle used to identify stored values. | |
Pairing heap implementation.
Code is mainly based on orginal paper "The Pairing Heap: A New Form of Self-Adjusting Heap" by Fredman, Sedgewick, Sleator and Tarjan.
T | Denotes value type of inserted elements. |
C | Denotes comparison functor determining value ordering. |
Definition at line 70 of file PairingHeap.h.
|
private |
Definition at line 71 of file PairingHeap.h.
|
explicit |
Creates empty pairing heap.
cmp | Comparison functor determining value ordering. |
initialSize | ignored by this implementation. |
Definition at line 154 of file PairingHeap.h.
|
virtual |
Destructs pairing heap.
If the heap is not empty, destructors of contained elements are called and used storage is deallocated.
Definition at line 158 of file PairingHeap.h.
|
override |
Decreases value of the given heapNode
to value
.
Behaviour of this function is undefined if node does not belong to a the heap or new value is greater than old one.
heapNode | A node for which the value is to be decreased. |
value | A new value for the node. |
Definition at line 186 of file PairingHeap.h.
|
inlinestaticprivate |
Makes child
node a child of parent
node.
Definition at line 255 of file PairingHeap.h.
|
override |
Merges in values of other
heap.
After merge other
heap becomes empty and is valid for further usage.
other | A heap to be merged in. |
Definition at line 195 of file PairingHeap.h.
|
inlineprivate |
Merges lists of heaps a
and b
. Returns resulting list.
Definition at line 244 of file PairingHeap.h.
|
inlineprivate |
Pairs list of heaps given as heapNode
. Returns resulting list.
Definition at line 201 of file PairingHeap.h.
|
overridevirtual |
Removes the top element from the heap.
Behaviour of this function is undefined if the heap is empty.
Implements ogdf::HeapBase< PairingHeap< T, C >, PairingHeapNode< T >, T, C >.
Definition at line 178 of file PairingHeap.h.
|
overridevirtual |
Inserts a new node with given value
into a heap.
value | A value to be inserted. |
Implements ogdf::HeapBase< PairingHeap< T, C >, PairingHeapNode< T >, T, C >.
Definition at line 170 of file PairingHeap.h.
|
inlinestaticprivate |
Releases memory occupied by list of heaps given as heapNode
.
Definition at line 279 of file PairingHeap.h.
|
inlineoverridevirtual |
Returns reference to the top element in the heap.
Implements ogdf::HeapBase< PairingHeap< T, C >, PairingHeapNode< T >, T, C >.
Definition at line 164 of file PairingHeap.h.
|
inlinestaticprivate |
Removes heapNode
from its parent children list.
Definition at line 265 of file PairingHeap.h.
|
inlineoverride |
Returns the value of the node.
heapNode | The nodes handle |
Definition at line 134 of file PairingHeap.h.
|
private |
Root node of the heap.
Definition at line 137 of file PairingHeap.h.