48 template<
typename,
typename>
88template<
typename T,
typename C = std::less<T>>
99 explicit FibonacciHeap(
const C& cmp = C(),
int initialSize = -1);
110 const T&
top()
const override;
162 std::array<FibonacciHeapNode<T>*,
sizeof(size_t) * 8>
m_ranked;
184template<
typename T,
typename C>
190template<
typename T,
typename C>
195template<
typename T,
typename C>
197 if (heapNode ==
nullptr) {
203 release(heapNode->
child);
208 }
while (heapNode !=
end);
211template<
typename T,
typename C>
214 return m_minimal->value;
217template<
typename T,
typename C>
220 splice(m_knot, heapNode);
222 if (m_minimal ==
nullptr || this->comparator()(heapNode->
value, m_minimal->value)) {
223 m_minimal = heapNode;
229template<
typename T,
typename C>
232 if (m_knot->next->next == m_knot && m_knot->next->child ==
nullptr) {
233 m_knot->
prev = m_knot->next = m_knot;
243 m_minimal = m_knot->next;
244 for (
auto it = m_knot->next->next; it != m_knot; it = it->next) {
245 if (this->comparator()(it->value, m_minimal->value)) {
251template<
typename T,
typename C>
253 heapNode->
value = value;
254 if (this->comparator()(heapNode->
value, m_minimal->value)) {
255 m_minimal = heapNode;
261template<
typename T,
typename C>
271 if (this->comparator()(other.
m_minimal->value, m_minimal->value)) {
277template<
typename T,
typename C>
279 if (m_minimal->child) {
287 }
while (it != m_minimal->
child);
293template<
typename T,
typename C>
297 for (
auto it = m_knot->next; it != m_knot;) {
301 maxr = std::max(
r, maxr);
302 while (m_ranked[
r]) {
303 if (this->comparator()(m_ranked[
r]->value, it->value)) {
304 link(m_ranked[
r], it);
307 link(it, m_ranked[
r]);
309 m_ranked[
r] =
nullptr;
311 maxr = std::max(maxr,
r);
318 for (
size_t i = 0; i <= maxr; i++) {
319 m_ranked[i] =
nullptr;
323template<
typename T,
typename C>
330 splice(root->
child, child);
337template<
typename T,
typename C>
339 heapNode->
prev->next = heapNode->
next;
340 heapNode->
next->prev = heapNode->
prev;
341 heapNode->
next = heapNode;
342 heapNode->
prev = heapNode;
345template<
typename T,
typename C>
348 other->
prev->next = m_knot->next;
349 m_knot->next = other;
350 other->
prev = m_knot;
353template<
typename T,
typename C>
356 target->
next->prev = heapNode;
358 target->
next = heapNode;
359 heapNode->
prev = target;
362template<
typename T,
typename C>
366 if (parent ==
nullptr) {
372 if (parent->
rank == 0) {
373 parent->
child =
nullptr;
374 }
else if (parent->
child == heapNode) {
378 heapNode->
parent =
nullptr;
379 splice(m_knot, heapNode);
Interface for heap implementations.
Basic declarations, included by all source files.
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.
The namespace for all OGDF objects.
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
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.