Heap realized by a data array. More...
#include <ogdf/basic/heap/BinaryHeap.h>
Classes | |
struct | HeapEntry |
Public Member Functions | |
BinaryHeap (const C &comp=C(), int initialSize=128) | |
Initializes an empty binary heap. More... | |
virtual | ~BinaryHeap () |
int | capacity () const |
Returns the current size. More... | |
void | clear () |
Reinitializes the data structure. More... | |
void | decrease (int *handle, const T &value) override |
Decreases a single value. More... | |
bool | empty () const |
Returns true iff the heap is empty. More... | |
void | pop () override |
Removes the topmost value from the heap. More... | |
int * | push (const T &value) override |
Inserts a value into the heap. More... | |
int | size () const |
Returns the number of stored elements. More... | |
const T & | top () const override |
Returns the topmost value in the heap. More... | |
const T & | value (int *handle) const override |
Returns the value of that handle. More... | |
![]() | |
HeapBase (std::less< T > const &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 | merge (BinaryHeap< 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... | |
Private Types | |
using | base_type = HeapBase< BinaryHeap< T, C >, int, T, C > |
Private Member Functions | |
int | arrayBound (int arraySize) |
bool | hasLeft (int num) |
Returns true if left child exists. More... | |
bool | hasRight (int num) |
Returns true if right child exists. More... | |
int | higherArrayBound (int arraySize) |
int | higherArraySize (int arraySize) |
void | init (int initialSize) |
int | leftChildIndex (int num) |
Array index of left child. More... | |
int | lowerArrayBound (int arraySize) |
int | lowerArraySize (int arraySize) |
int | parentIndex (int num) |
Array index of parent node. More... | |
int | rightChildIndex (int num) |
Array index of right child. More... | |
void | siftDown (int pos) |
Establishes heap property by moving element down in heap if necessary. More... | |
void | siftUp (int pos) |
Establishes heap property by moving element up in heap if necessary. More... | |
Private Attributes | |
int | m_arraySize |
HeapEntry * | m_heapArray |
int | m_initialSize |
int | m_size |
Additional Inherited Members | |
![]() | |
using | Handle = int * |
The type of handle used to identify stored values. More... | |
Heap realized by a data array.
This heap implementation does not support merge operations.
T | Denotes value type of inserted elements. |
C | Denotes comparison functor determining value ordering. |
Definition at line 50 of file BinaryHeap.h.
|
private |
Definition at line 53 of file BinaryHeap.h.
|
explicit |
Initializes an empty binary heap.
comp | Comparison functor determining value ordering. |
initialSize | The intial capacity of this heap. Used to allocate an adequate amount of memory. |
Definition at line 287 of file BinaryHeap.h.
|
inlinevirtual |
Definition at line 65 of file BinaryHeap.h.
|
inlineprivate |
Definition at line 172 of file BinaryHeap.h.
|
inline |
Returns the current size.
Definition at line 112 of file BinaryHeap.h.
void ogdf::BinaryHeap< T, C >::clear |
Reinitializes the data structure.
Deletes the array and reallocates it with size that was passed at construction time.
Definition at line 306 of file BinaryHeap.h.
|
overridevirtual |
Decreases a single value.
handle | The handle of the value to be decreased |
value | The decreased value. This must be less than the former value |
Implements ogdf::HeapBase< BinaryHeap< T, std::less< T > >, int, T, std::less< T > >.
Definition at line 269 of file BinaryHeap.h.
|
inline |
Returns true iff the heap is empty.
Definition at line 118 of file BinaryHeap.h.
|
inlineprivate |
Returns true if left child exists.
Definition at line 157 of file BinaryHeap.h.
|
inlineprivate |
Returns true if right child exists.
Definition at line 164 of file BinaryHeap.h.
|
inlineprivate |
Definition at line 173 of file BinaryHeap.h.
|
inlineprivate |
Definition at line 174 of file BinaryHeap.h.
|
private |
Definition at line 294 of file BinaryHeap.h.
|
inlineprivate |
Array index of left child.
Definition at line 143 of file BinaryHeap.h.
|
inlineprivate |
Definition at line 175 of file BinaryHeap.h.
|
inlineprivate |
Definition at line 176 of file BinaryHeap.h.
|
inlineprivate |
Array index of parent node.
Definition at line 136 of file BinaryHeap.h.
|
overridevirtual |
Removes the topmost value from the heap.
Implements ogdf::HeapBase< BinaryHeap< T, std::less< T > >, int, T, std::less< T > >.
Definition at line 241 of file BinaryHeap.h.
|
overridevirtual |
Inserts a value into the heap.
value | The value to be inserted |
Implements ogdf::HeapBase< BinaryHeap< T, std::less< T > >, int, T, std::less< T > >.
Definition at line 205 of file BinaryHeap.h.
|
inlineprivate |
Array index of right child.
Definition at line 150 of file BinaryHeap.h.
|
private |
Establishes heap property by moving element down in heap if necessary.
Definition at line 341 of file BinaryHeap.h.
|
private |
Establishes heap property by moving element up in heap if necessary.
Definition at line 316 of file BinaryHeap.h.
|
inline |
Returns the number of stored elements.
Definition at line 115 of file BinaryHeap.h.
|
override |
Returns the topmost value in the heap.
Definition at line 199 of file BinaryHeap.h.
|
overridevirtual |
Returns the value of that handle.
handle | The handle |
Implements ogdf::HeapBase< BinaryHeap< T, std::less< T > >, int, T, std::less< T > >.
Definition at line 278 of file BinaryHeap.h.
|
private |
Definition at line 191 of file BinaryHeap.h.
|
private |
Definition at line 185 of file BinaryHeap.h.
|
private |
Definition at line 194 of file BinaryHeap.h.
|
private |
Definition at line 188 of file BinaryHeap.h.