48 typename C=std::less<T>
63 explicit BinaryHeap(
const C &comp = C(),
int initialSize = 128);
67 for(
int i = 1; i <=
m_size; i++) {
80 const T &
top()
const override;
101 void decrease(
int *handle,
const T &value)
override;
109 const T &
value(
int *handle)
const override;
177 void init(
int initialSize);
181 int *handle =
nullptr;
198 template <
typename T,
typename C>
201 return value(&firstIndex);
204 template <
typename T,
typename C>
229 int *result = entry.
handle;
240 template <
typename T,
typename C>
252 if (m_size < m_arraySize / 3 && m_arraySize > 2*
m_initialSize - 1) {
255 for (
int i = 1; i <=
m_size ; i++) {
268 template <
typename T,
typename C>
277 template <
typename T,
typename C>
286 template <
typename T,
typename C>
293 template <
typename T,
typename C>
305 template <
typename T,
typename C>
307 for(
int i = 1; i <=
m_size; i++) {
315 template <
typename T,
typename C>
340 template <
typename T,
typename C>
347 if (pos >=
m_size/2 + 1) {
int parentIndex(int num)
Array index of parent node.
const T & top() const override
Returns the topmost value in the heap.
void siftUp(int pos)
Establishes heap property by moving element up in heap if necessary.
bool empty() const
Returns true iff the heap is empty.
Interface for heap implementations.
int * push(const T &value) override
Inserts a value into the heap.
int lowerArraySize(int arraySize)
int higherArrayBound(int arraySize)
int size() const
Returns the number of stored elements.
int leftChildIndex(int num)
Array index of left child.
void decrease(int *handle, const T &value) override
Decreases a single value.
bool hasRight(int num)
Returns true if right child exists.
virtual const C & comparator() const
Returns the comparator used to sort the values in the heap.
int higherArraySize(int arraySize)
void init(int initialSize)
void clear()
Reinitializes the data structure.
Heap realized by a data array.
bool hasLeft(int num)
Returns true if left child exists.
Common interface for all heap classes.
int arrayBound(int arraySize)
void siftDown(int pos)
Establishes heap property by moving element down in heap if necessary.
The namespace for all OGDF objects.
int rightChildIndex(int num)
Array index of right child.
const T & value(int *handle) const override
Returns the value of that handle.
int capacity() const
Returns the current size.
BinaryHeap(const C &comp=C(), int initialSize=128)
Initializes an empty binary heap.
int lowerArrayBound(int arraySize)
void pop() override
Removes the topmost value from the heap.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.