Randomized meldable heap implementation. More...
#include <ogdf/basic/heap/RMHeap.h>
Public Member Functions | |
RMHeap (const C &cmp=C(), int initialSize=-1) | |
Creates empty randomized meldable heap. More... | |
virtual | ~RMHeap () |
Destructs the heap. More... | |
void | decrease (RMHeapNode< T > *heapNode, const T &value) override |
Decreases value of the given heapNode to value . More... | |
void | merge (RMHeap< T, C > &other) override |
Merges in values of other heap. More... | |
void | pop () override |
Removes the top element from the heap. More... | |
RMHeapNode< 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 (RMHeapNode< T > *heapNode) const override |
Returns the value of the node. More... | |
Public Member Functions inherited from ogdf::HeapBase< RMHeap< T, std::less< T > >, RMHeapNode< T >, T, std::less< T > > | |
HeapBase (const std::less< T > &comp=std::less< T >()) | |
virtual const std::less< T > & | 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 void | merge (RMHeap< T, std::less< T > > &other) |
Merges in values of other heap. 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< RMHeap< T, C >, RMHeapNode< T >, T, C > |
Private Member Functions | |
RMHeapNode< T > * | merge (RMHeapNode< T > *a, RMHeapNode< T > *b) |
Recursively merges heaps a and b . Returns resulting heap. More... | |
void | remove (RMHeapNode< T > *heapNode) |
Removes given heapNode from the main tree (does not free memory!). More... | |
Static Private Member Functions | |
static void | release (RMHeapNode< T > *heapNode) |
Recursively releases memory occupied by heap pointed by heapNode . More... | |
Private Attributes | |
std::default_random_engine | m_rand |
Random values generator. More... | |
RMHeapNode< T > * | m_root |
Root node of the heap. More... | |
Additional Inherited Members | |
Public Types inherited from ogdf::HeapBase< RMHeap< T, std::less< T > >, RMHeapNode< T >, T, std::less< T > > | |
using | Handle = RMHeapNode< T > * |
The type of handle used to identify stored values. More... | |
Randomized meldable heap implementation.
Code of meld (also known as merge) operation is solely based on Wikipedia article. Other methods are based on my intuitions and make use of melding.
For random number generation it uses default generator provided by the C++11 standard. In the future, it should be possible to provide custom random device, generator and seed.
T | Denotes value type of inserted elements. |
C | Denotes comparison functor determining value ordering. |
|
private |
|
explicit |
|
virtual |
|
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. |
|
override |
|
private |
|
overridevirtual |
Removes the top element from the heap.
Behaviour of this function is undefined if the heap is empty.
Implements ogdf::HeapBase< RMHeap< T, std::less< T > >, RMHeapNode< T >, T, std::less< T > >.
|
overridevirtual |
Inserts a new node with given value
into a heap.
value | A value to be inserted. |
Implements ogdf::HeapBase< RMHeap< T, std::less< T > >, RMHeapNode< T >, T, std::less< T > >.
|
staticprivate |
|
private |
|
override |
|
inlineoverride |
|
private |
|
private |