46 template<
typename,
typename>
86template<
typename T,
typename C = std::less<T>>
108 const T&
top()
const override;
182template<
typename T,
typename C>
188template<
typename T,
typename C>
193template<
typename T,
typename C>
209template<
typename T,
typename C>
212 return m_minimal->value;
215template<
typename T,
typename C>
220 if (m_minimal ==
nullptr || this->comparator()(
heapNode->value, m_minimal->value)) {
227template<
typename T,
typename C>
230 if (m_knot->next->next == m_knot && m_knot->next->child ==
nullptr) {
231 m_knot->prev = m_knot->next = m_knot;
241 m_minimal = m_knot->next;
242 for (
auto it = m_knot->next->next; it != m_knot; it = it->next) {
243 if (this->comparator()(it->value, m_minimal->value)) {
249template<
typename T,
typename C>
252 if (this->comparator()(
heapNode->value, m_minimal->value)) {
259template<
typename T,
typename C>
261 if (
other.m_minimal ==
nullptr) {
266 detach(
other.m_knot);
269 if (this->comparator()(
other.m_minimal->value, m_minimal->value)) {
270 m_minimal =
other.m_minimal;
272 other.m_minimal =
nullptr;
275template<
typename T,
typename C>
277 if (m_minimal->child) {
285 }
while (it != m_minimal->
child);
291template<
typename T,
typename C>
295 for (
auto it = m_knot->next; it != m_knot;) {
300 while (m_ranked[
r]) {
301 if (this->comparator()(m_ranked[
r]->value, it->value)) {
302 link(m_ranked[
r], it);
305 link(it, m_ranked[
r]);
307 m_ranked[
r] =
nullptr;
316 for (
size_t i = 0; i <=
maxr; i++) {
317 m_ranked[i] =
nullptr;
321template<
typename T,
typename C>
328 splice(root->
child, child);
335template<
typename T,
typename C>
343template<
typename T,
typename C>
345 m_knot->next->prev =
other->prev;
346 other->prev->next = m_knot->next;
347 m_knot->next =
other;
348 other->prev = m_knot;
351template<
typename T,
typename C>
360template<
typename T,
typename C>
364 if (parent ==
nullptr) {
370 if (parent->
rank == 0) {
371 parent->
child =
nullptr;
Interface for heap implementations.
Fibonacci heap implementation.
virtual ~FibonacciHeap()
Destructs the heap.
void merge(FibonacciHeap< T, C > &other) override
Merges in values of other heap.
void detach(FibonacciHeapNode< T > *heapNode)
Detaches given heapNode from its list and makes it self-circulate.
void compress()
Reduces number of trees inside a heap by linking ones with same degree.
std::array< FibonacciHeapNode< T > *, sizeof(size_t) *8 > m_ranked
Used to compress trees.
void link(FibonacciHeapNode< T > *root, FibonacciHeapNode< T > *child)
Makes child node a child of root node.
void splice(FibonacciHeapNode< T > *target, FibonacciHeapNode< T > *heapNode)
Moves heapNode from its list to the target list.
void decrease(FibonacciHeapNode< T > *heapNode, const T &value) override
Decreases value of the given heapNode to value.
FibonacciHeapNode< T > * m_knot
Used for efficient tree list manipulation.
FibonacciHeapNode< T > * m_minimal
Handle to the tree with lowest root priority.
void release(FibonacciHeapNode< T > *heapNode)
Recursively releases memory starting at heapNode.
void restore(FibonacciHeapNode< T > *heapNode)
Restores heap ordering in heapNode by making (cascade) cut.
void pop() override
Removes the top element from the heap.
void remove()
Removes minimal tree and moves its children to tree list.
const T & value(FibonacciHeapNode< T > *heapNode) const override
Returns the value of the node.
FibonacciHeap(const C &cmp=C(), int initialSize=-1)
Creates empty Fibonacci heap.
const T & top() const override
Returns reference to the top element in the heap.
FibonacciHeapNode< T > * push(const T &value) override
Inserts a new node with given value into a heap.
Common interface for all heap classes.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
bool marked
Indicates whether node is marked or not.
FibonacciHeapNode< T > * child
First child of the node.
FibonacciHeapNode(const T &nodeValue)
Creates heap node with a given nodeValue.
size_t rank
Determines rank of a node.
FibonacciHeapNode< T > * parent
Parent of the node.
FibonacciHeapNode< T > * next
Next sibling of the node.
T value
Value contained in the node.
FibonacciHeapNode()
Creates empty root node.
FibonacciHeapNode< T > * prev
Previous sibling of the node.