Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ogdf::RMHeap< T, C > Class Template Reference

Randomized meldable heap implementation. More...

#include <ogdf/basic/heap/RMHeap.h>

+ Inheritance diagram for ogdf::RMHeap< T, C >:

Public Member Functions

 RMHeap (const C &cmp=C(), int initialSize=-1)
 Creates empty randomized meldable heap.
 
virtual ~RMHeap ()
 Destructs the heap.
 
void decrease (RMHeapNode< T > *heapNode, const T &value) override
 Decreases value of the given heapNode to value.
 
void merge (RMHeap< T, C > &other) override
 Merges in values of other heap.
 
void pop () override
 Removes the top element from the heap.
 
RMHeapNode< 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 (RMHeapNode< T > *heapNode) const override
 Returns the value of the node.
 
- Public Member Functions inherited from ogdf::HeapBase< IMPL, H, 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 (IMPL &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< 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.
 
void remove (RMHeapNode< T > *heapNode)
 Removes given heapNode from the main tree (does not free memory!).
 

Static Private Member Functions

static void release (RMHeapNode< T > *heapNode)
 Recursively releases memory occupied by heap pointed by heapNode.
 

Private Attributes

std::default_random_engine m_rand
 Random values generator.
 
RMHeapNode< T > * m_root
 Root node of the heap.
 

Additional Inherited Members

- Public Types inherited from ogdf::HeapBase< IMPL, H, T, C >
using Handle = H *
 The type of handle used to identify stored values.
 

Detailed Description

template<typename T, typename C = std::less<T>>
class ogdf::RMHeap< T, C >

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.

Template Parameters
TDenotes value type of inserted elements.
CDenotes comparison functor determining value ordering.

Definition at line 75 of file RMHeap.h.

Member Typedef Documentation

◆ base_type

template<typename T , typename C = std::less<T>>
using ogdf::RMHeap< T, C >::base_type = HeapBase<RMHeap<T, C>, RMHeapNode<T>, T, C>
private

Definition at line 76 of file RMHeap.h.

Constructor & Destructor Documentation

◆ RMHeap()

template<typename T , typename C >
ogdf::RMHeap< T, C >::RMHeap ( const C &  cmp = C(),
int  initialSize = -1 
)
explicit

Creates empty randomized meldable heap.

Parameters
cmpComparison functor determining value ordering.
initialSizeignored by this implementation.

Definition at line 155 of file RMHeap.h.

◆ ~RMHeap()

template<typename T , typename C >
ogdf::RMHeap< T, C >::~RMHeap ( )
virtual

Destructs the heap.

If the heap is not empty, destructors of contained elements are called and used storage is deallocated.

Definition at line 159 of file RMHeap.h.

Member Function Documentation

◆ decrease()

template<typename T , typename C >
void ogdf::RMHeap< T, C >::decrease ( RMHeapNode< T > *  heapNode,
const T &  value 
)
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.

Parameters
heapNodeA node for which the value is to be decreased.
valueA new value for the node.

Definition at line 187 of file RMHeap.h.

◆ merge() [1/2]

template<typename T , typename C >
void ogdf::RMHeap< T, C >::merge ( RMHeap< T, C > &  other)
override

Merges in values of other heap.

After merge other heap becomes empty and is valid for further usage.

Parameters
otherA heap to be merged in.

Definition at line 202 of file RMHeap.h.

◆ merge() [2/2]

template<typename T , typename C >
RMHeapNode< T > * ogdf::RMHeap< T, C >::merge ( RMHeapNode< T > *  a,
RMHeapNode< T > *  b 
)
private

Recursively merges heaps a and b. Returns resulting heap.

Definition at line 208 of file RMHeap.h.

◆ pop()

template<typename T , typename C >
void ogdf::RMHeap< T, C >::pop ( )
overridevirtual

Removes the top element from the heap.

Behaviour of this function is undefined if the heap is empty.

Implements ogdf::HeapBase< IMPL, H, T, C >.

Definition at line 177 of file RMHeap.h.

◆ push()

template<typename T , typename C >
RMHeapNode< T > * ogdf::RMHeap< T, C >::push ( const T &  value)
overridevirtual

Inserts a new node with given value into a heap.

Parameters
valueA value to be inserted.
Returns
Handle to the inserted node.

Implements ogdf::HeapBase< IMPL, H, T, C >.

Definition at line 169 of file RMHeap.h.

◆ release()

template<typename T , typename C >
void ogdf::RMHeap< T, C >::release ( RMHeapNode< T > *  heapNode)
staticprivate

Recursively releases memory occupied by heap pointed by heapNode.

Definition at line 259 of file RMHeap.h.

◆ remove()

template<typename T , typename C >
void ogdf::RMHeap< T, C >::remove ( RMHeapNode< T > *  heapNode)
private

Removes given heapNode from the main tree (does not free memory!).

Definition at line 246 of file RMHeap.h.

◆ top()

template<typename T , typename C >
const T & ogdf::RMHeap< T, C >::top ( ) const
overridevirtual

Returns reference to the top element in the heap.

Implements ogdf::HeapBase< IMPL, H, T, C >.

Definition at line 164 of file RMHeap.h.

◆ value()

template<typename T , typename C = std::less<T>>
const T & ogdf::RMHeap< T, C >::value ( RMHeapNode< T > *  heapNode) const
inlineoverride

Returns the value of the node.

Parameters
heapNodeThe nodes handle
Returns
the value of the node

Definition at line 139 of file RMHeap.h.

Member Data Documentation

◆ m_rand

template<typename T , typename C = std::less<T>>
std::default_random_engine ogdf::RMHeap< T, C >::m_rand
private

Random values generator.

Definition at line 142 of file RMHeap.h.

◆ m_root

template<typename T , typename C = std::less<T>>
RMHeapNode<T>* ogdf::RMHeap< T, C >::m_root
private

Root node of the heap.

Definition at line 143 of file RMHeap.h.


The documentation for this class was generated from the following file: