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. More... | |
virtual | ~PairingHeap () |
Destructs pairing heap. More... | |
void | decrease (PairingHeapNode< T > *heapNode, const T &value) override |
Decreases value of the given heapNode to value . More... | |
void | merge (PairingHeap< T, C > &other) override |
Merges in values of other heap. More... | |
void | pop () override |
Removes the top element from the heap. More... | |
PairingHeapNode< T > * | push (const T &value) override |
Inserts a new node with given value into a heap. More... | |
const T & | top () const override |
Returns reference to the top element in the heap. More... | |
const T & | value (PairingHeapNode< T > *heapNode) const override |
Returns the value of the node. More... | |
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. More... | |
virtual void | decrease (Handle handle, const T &value)=0 |
Decreases a single value. More... | |
virtual const T & | top () const=0 |
Returns the topmost value in the heap. More... | |
virtual const T & | value (const Handle handle) const=0 |
Returns the value of that handle. More... | |
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. More... | |
PairingHeapNode< T > * | pair (PairingHeapNode< T > *heapNode) |
Pairs list of heaps given as heapNode . Returns resulting list. More... | |
Static Private Member Functions | |
static void | link (PairingHeapNode< T > *parent, PairingHeapNode< T > *child) |
Makes child node a child of parent node. More... | |
static void | release (PairingHeapNode< T > *heapNode) |
Releases memory occupied by list of heaps given as heapNode . More... | |
static void | unlink (PairingHeapNode< T > *heapNode) |
Removes heapNode from its parent children list. More... | |
Private Attributes | |
PairingHeapNode< T > * | m_root |
Root node of the heap. More... | |
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. More... | |
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 71 of file PairingHeap.h.
|
private |
Definition at line 72 of file PairingHeap.h.
|
explicit |
Creates empty pairing heap.
cmp | Comparison functor determining value ordering. |
initialSize | ignored by this implementation. |
Definition at line 155 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 159 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 187 of file PairingHeap.h.
|
inlinestaticprivate |
Makes child
node a child of parent
node.
Definition at line 262 of file PairingHeap.h.
|
overridevirtual |
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. |
Reimplemented from ogdf::HeapBase< PairingHeap< T, C >, PairingHeapNode< T >, T, C >.
Definition at line 196 of file PairingHeap.h.
|
inlineprivate |
Merges lists of heaps a
and b
. Returns resulting list.
Definition at line 245 of file PairingHeap.h.
|
inlineprivate |
Pairs list of heaps given as heapNode
. Returns resulting list.
Definition at line 202 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 179 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 171 of file PairingHeap.h.
|
inlinestaticprivate |
Releases memory occupied by list of heaps given as heapNode
.
Definition at line 286 of file PairingHeap.h.
|
inlineoverride |
Returns reference to the top element in the heap.
Definition at line 165 of file PairingHeap.h.
|
inlinestaticprivate |
Removes heapNode
from its parent children list.
Definition at line 272 of file PairingHeap.h.
|
inlineoverride |
Returns the value of the node.
heapNode | The nodes handle |
Definition at line 135 of file PairingHeap.h.
|
private |
Root node of the heap.
Definition at line 138 of file PairingHeap.h.