|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Implementation of a Fibonacci Heap priority queue. More...
#include <tpl_fibonacci_heap.H>
Classes | |
| struct | Node |
| Represents a node in the Fibonacci Heap. More... | |
Public Types | |
| using | value_type = T |
| Type alias for the element type. | |
| using | key_compare = Compare |
| Type alias for the comparison functor. | |
| using | handle_type = Node * |
| Type alias for node handles. | |
Public Member Functions | |
| Fibonacci_Heap (Compare compare=Compare()) noexcept(std::is_nothrow_copy_constructible_v< Compare >) | |
| Default constructor. | |
| template<typename... Args> | |
| Fibonacci_Heap (std::in_place_t, Args &&... args) noexcept(std::is_nothrow_constructible_v< Compare, Args &&... >) | |
| Constructor with in-place comparator construction. | |
| ~Fibonacci_Heap () | |
| Destructor. | |
| Fibonacci_Heap (const Fibonacci_Heap &)=delete | |
| Copy constructor is disabled (use merge or manual copy) | |
| Fibonacci_Heap & | operator= (const Fibonacci_Heap &)=delete |
| Copy assignment is disabled (use merge or manual copy) | |
| Fibonacci_Heap (Fibonacci_Heap &&other) noexcept(std::is_nothrow_move_constructible_v< Compare >) | |
| Move constructor. | |
| Fibonacci_Heap & | operator= (Fibonacci_Heap &&other) noexcept(std::is_nothrow_move_assignable_v< Compare > and std::is_nothrow_destructible_v< T >) |
| Move assignment operator. | |
| void | swap (Fibonacci_Heap &other) noexcept(std::is_nothrow_swappable_v< Compare >) |
| Swaps contents with another heap. | |
| Node * | insert (const T &val) |
| Inserts a new element (copy). | |
| Node * | insert (T &&val) |
| Inserts a new element (move). | |
| template<typename... Args> | |
| Node * | emplace (Args &&... args) |
| Constructs and inserts an element in-place. | |
| const T & | get_min () const |
| Returns the minimum element without removing it. | |
| Node * | get_min_node () const noexcept |
| Returns a pointer to the minimum node. | |
| T | extract_min () |
| Extracts and returns the minimum element. | |
| void | decrease_key (Node *x, const T &k) |
| Decreases the key of a node. | |
| void | decrease_key (Node *x, T &&k) |
| Decreases the key of a node (move version). | |
| Node * | update_key (Node *x, const T &k) |
| Updates the key of a node (increase or decrease). | |
| void | delete_node (Node *x) |
| Deletes a specific node from the heap. | |
| void | merge (Fibonacci_Heap &other) |
| Merges another heap into this one. | |
| void | merge (Fibonacci_Heap &&other) |
| Merges another heap into this one (rvalue version). | |
| bool | is_empty () const noexcept |
| Checks if the heap is empty. | |
| size_t | size () const noexcept |
| Returns the number of elements in the heap. | |
| void | clear () noexcept(std::is_nothrow_destructible_v< T >) |
| Removes all elements from the heap. | |
| bool | empty () const noexcept |
| void | pop () |
| const T & | top () const |
| Compare | key_comp () const |
| Returns the comparison functor. | |
| Compare & | get_compare () noexcept |
| Returns the comparison functor that orders the heap. | |
Private Member Functions | |
| void | consolidate () |
| Consolidates the root list after extract_min. | |
| void | cut (Node *x, Node *y) |
| Cuts a node from its parent and adds it to the root list. | |
| void | cascading_cut (Node *y) |
| Performs cascading cut operation. | |
| void | take_root_out (Node *z) noexcept |
| Takes a root out of the root list, after putting its children in it as roots. | |
| void | put_root_back (Node *z, Node *min) noexcept |
| Undoes take_root_out() after a comparison threw. | |
| void | delete_all_nodes (Node *node) |
| Deletes all the nodes of the trees in a circular list. | |
| void | add_to_root_list (Node *node) |
| Adds a node to the root list. | |
| Node * | insert_new_node (Node *node) |
Static Private Member Functions | |
| static void | link (Node *y, Node *x) |
| Links two trees of the same degree. | |
Private Attributes | |
| Node * | min_node = nullptr |
| Pointer to the current minimum root. | |
| size_t | num_nodes = 0 |
| Number of elements stored in the heap. | |
| Compare | cmp |
| Comparison functor used to order nodes. | |
| std::vector< Node * > | consolidate_array_ |
| Reusable scratch array for Fibonacci_Heap::consolidate(). | |
Static Private Attributes | |
| static constexpr size_t | MAX_DEGREE = 128 |
| Maximum degree tracked during consolidation. | |
Related Symbols | |
(Note that these are not member symbols.) | |
| template<typename T , class Compare > | |
| void | swap (Fibonacci_Heap< T, Compare > &a, Fibonacci_Heap< T, Compare > &b) noexcept(noexcept(a.swap(b))) |
| Swaps two Fibonacci heaps. | |
Implementation of a Fibonacci Heap priority queue.
A Fibonacci Heap is a collection of heap-ordered trees that supports a rich set of operations with excellent amortized time complexity. It is particularly well-suited for graph algorithms like Dijkstra's shortest path and Prim's minimum spanning tree where decrease-key operations are frequent.
| Operation | Time Complexity |
|---|---|
| insert | O(1) |
| get_min | O(1) |
| extract_min | O(log n) |
| decrease_key | O(1) |
| delete_node | O(log n) |
| merge | O(1) |
| is_empty | O(1) |
| size | O(1) |
| T | The data type of elements stored in the heap. |
| Compare | The comparison functor (defaults to Aleph::less<T> for a min-heap). Use Aleph::greater<T> for a max-heap. |
Definition at line 115 of file tpl_fibonacci_heap.H.
| using Aleph::Fibonacci_Heap< T, Compare >::handle_type = Node * |
Type alias for node handles.
Definition at line 534 of file tpl_fibonacci_heap.H.
| using Aleph::Fibonacci_Heap< T, Compare >::key_compare = Compare |
Type alias for the comparison functor.
Definition at line 531 of file tpl_fibonacci_heap.H.
| using Aleph::Fibonacci_Heap< T, Compare >::value_type = T |
Type alias for the element type.
Definition at line 528 of file tpl_fibonacci_heap.H.
|
inlineexplicitnoexcept |
Default constructor.
Creates an empty heap using a copy of compare to order keys.
| compare | Comparison functor (defaults to Compare()). |
Definition at line 543 of file tpl_fibonacci_heap.H.
|
inlineexplicitnoexcept |
Constructor with in-place comparator construction.
Allows constructing the comparator from arbitrary arguments. Use std::in_place as first argument to disambiguate.
| Args | Types of comparator constructor arguments |
| args | Arguments forwarded to Compare's constructor |
Definition at line 561 of file tpl_fibonacci_heap.H.
|
inline |
Destructor.
Deallocates all nodes. Runs in O(n) time.
Definition at line 573 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::clear().
|
delete |
Copy constructor is disabled (use merge or manual copy)
|
inlinenoexcept |
Move constructor.
Transfers ownership of all nodes from other to this heap. The source heap becomes empty.
| other | The heap to move from |
Definition at line 592 of file tpl_fibonacci_heap.H.
|
inlineprivate |
Adds a node to the root list.
The keys are compared before the node enters the list, so that if the comparison throws the heap is as it was.
| node | The node to add (must not be in any list) |
Definition at line 485 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::cmp, Aleph::Fibonacci_Heap< T, Compare >::Node::data, Aleph::Fibonacci_Heap< T, Compare >::Node::left, Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::Node::parent, and Aleph::Fibonacci_Heap< T, Compare >::Node::right.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::insert_new_node().
|
inlineprivate |
Performs cascading cut operation.
If y has lost a child before (mark == true), cut it from its parent and recursively check the parent. This maintains the amortized O(1) decrease_key complexity.
| y | The node to potentially cut |
Definition at line 345 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::cut(), Aleph::Fibonacci_Heap< T, Compare >::Node::mark, Aleph::Fibonacci_Heap< T, Compare >::Node::parent, and y.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::decrease_key(), Aleph::Fibonacci_Heap< T, Compare >::decrease_key(), Aleph::Fibonacci_Heap< T, Compare >::delete_node(), Aleph::Fibonacci_Heap< T, Compare >::put_root_back(), and Aleph::Fibonacci_Heap< T, Compare >::update_key().
|
inlinenoexcept |
Removes all elements from the heap.
Deallocates all nodes and resets the heap to empty state.
Definition at line 1086 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::delete_all_nodes(), Aleph::Fibonacci_Heap< T, Compare >::min_node, and Aleph::Fibonacci_Heap< T, Compare >::num_nodes.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::~Fibonacci_Heap(), ArcFibonacciHeap< GT, Distance, Access_Heap_Node >::empty(), Aleph::Fibonacci_Heap< T, Compare >::operator=(), TEST(), and TEST().
|
inlineprivate |
Consolidates the root list after extract_min.
Ensures no two roots have the same degree by linking trees of equal degree until all roots have distinct degrees.
It allocates nothing: extract_min() and delete_node() reserve consolidate_array_ before they change the heap. If the comparison throws, every tree is still in the root list and min_node is one of its roots, perhaps not the minimum.
Definition at line 231 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::cmp, Aleph::Fibonacci_Heap< T, Compare >::consolidate_array_, Aleph::Fibonacci_Heap< T, Compare >::Node::data, Aleph::Fibonacci_Heap< T, Compare >::Node::degree, Aleph::Fibonacci_Heap< T, Compare >::Node::left, Aleph::Fibonacci_Heap< T, Compare >::link(), Aleph::Fibonacci_Heap< T, Compare >::MAX_DEGREE, Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::Node::parent, Aleph::Fibonacci_Heap< T, Compare >::Node::right, and y.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::delete_node(), Aleph::Fibonacci_Heap< T, Compare >::extract_min(), and Aleph::Fibonacci_Heap< T, Compare >::update_key().
|
inlineprivate |
Cuts a node from its parent and adds it to the root list.
| x | The node to cut |
| y | The parent of x |
Definition at line 313 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::Node::child, Aleph::Fibonacci_Heap< T, Compare >::Node::degree, Aleph::Fibonacci_Heap< T, Compare >::Node::left, Aleph::Fibonacci_Heap< T, Compare >::Node::mark, Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::Node::parent, Aleph::Fibonacci_Heap< T, Compare >::Node::right, and y.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::cascading_cut(), Aleph::Fibonacci_Heap< T, Compare >::decrease_key(), Aleph::Fibonacci_Heap< T, Compare >::decrease_key(), Aleph::Fibonacci_Heap< T, Compare >::delete_node(), Aleph::Fibonacci_Heap< T, Compare >::put_root_back(), and Aleph::Fibonacci_Heap< T, Compare >::update_key().
|
inline |
Decreases the key of a node.
Decreases the key of node x to the new value k. If this violates the heap property with x's parent, x is cut and added to the root list, potentially triggering cascading cuts.
| x | Handle to the node (returned by insert/emplace) |
| k | The new key value (must be <= current key) |
| std::invalid_argument | if x is nullptr |
| std::domain_error | if k > current key |
| anything | that the comparison throws. Then the heap is as it was, and x has its old key. |
| anything | that the assignment of the key throws. Then the heap is as it was but for the key of x, which is as the assignment left it: if that is not its old key, x may be out of order. |
Definition at line 798 of file tpl_fibonacci_heap.H.
References ah_domain_error_if, ah_invalid_argument_if, Aleph::and, Aleph::Fibonacci_Heap< T, Compare >::cascading_cut(), Aleph::Fibonacci_Heap< T, Compare >::cmp, Aleph::Fibonacci_Heap< T, Compare >::cut(), Aleph::Fibonacci_Heap< T, Compare >::Node::data, k, Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::Node::parent, and y.
Referenced by demo_fibonacci_heap(), demo_performance_comparison(), ArcFibonacciHeap< GT, Distance, Access_Heap_Node >::put_arc(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), and Aleph::Fibonacci_Heap< T, Compare >::update_key().
|
inline |
Decreases the key of a node (move version).
| x | Handle to the node |
| k | The new key value (moved into node) |
| std::invalid_argument | if x is nullptr |
| std::domain_error | if k > current key |
| anything | that the comparison or the assignment of the key throw, as the copy version; if the comparison throws, k is not moved from. |
Definition at line 833 of file tpl_fibonacci_heap.H.
References ah_domain_error_if, ah_invalid_argument_if, Aleph::and, Aleph::Fibonacci_Heap< T, Compare >::cascading_cut(), Aleph::Fibonacci_Heap< T, Compare >::cmp, Aleph::Fibonacci_Heap< T, Compare >::cut(), Aleph::Fibonacci_Heap< T, Compare >::Node::data, k, Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::Node::parent, and y.
|
inlineprivate |
Deletes all the nodes of the trees in a circular list.
Used by clear() for O(n) cleanup instead of O(n log n). Before deleting a node, it puts the children of the node in the list, right after it, so it needs no recursion: a tree can be as high as the heap is large.
| node | A node of the list, or nullptr |
Definition at line 453 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::Node::child, Aleph::Fibonacci_Heap< T, Compare >::Node::left, Aleph::next(), and Aleph::Fibonacci_Heap< T, Compare >::Node::right.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::clear().
|
inline |
Deletes a specific node from the heap.
Removes the node x from the heap regardless of its position.
| x | Handle to the node to delete |
| std::invalid_argument | if x is nullptr |
| anything | that the comparison throws. Then x is still in the heap, which has the elements that it had, the minimum among them, and every handle is valid; its trees may be linked otherwise. |
Definition at line 955 of file tpl_fibonacci_heap.H.
References ah_invalid_argument_if, Aleph::Fibonacci_Heap< T, Compare >::cascading_cut(), Aleph::Fibonacci_Heap< T, Compare >::consolidate(), Aleph::Fibonacci_Heap< T, Compare >::consolidate_array_, Aleph::Fibonacci_Heap< T, Compare >::cut(), Aleph::Fibonacci_Heap< T, Compare >::MAX_DEGREE, Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::num_nodes, Aleph::Fibonacci_Heap< T, Compare >::Node::parent, Aleph::Fibonacci_Heap< T, Compare >::put_root_back(), and Aleph::Fibonacci_Heap< T, Compare >::take_root_out().
|
inline |
Constructs and inserts an element in-place.
Constructs the element directly in the node using the provided arguments, avoiding unnecessary copies or moves.
| Args | Types of constructor arguments |
| args | Arguments to forward to T's constructor |
| anything | that the comparison throws. Then the heap is as it was. |
Definition at line 704 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::insert_new_node().
|
inlinenoexcept |
Definition at line 1096 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::is_empty().
|
inline |
Extracts and returns the minimum element.
Removes the minimum element from the heap and returns it. The heap is restructured (consolidated) after removal.
| std::underflow_error | if the heap is empty |
| anything | that the comparison throws. Then the heap has the elements that it had, the minimum among them, and every handle is valid; its trees may be linked otherwise. |
Definition at line 751 of file tpl_fibonacci_heap.H.
References ah_underflow_error_if, Aleph::Fibonacci_Heap< T, Compare >::consolidate(), Aleph::Fibonacci_Heap< T, Compare >::consolidate_array_, Aleph::Fibonacci_Heap< T, Compare >::Node::data, Aleph::Fibonacci_Heap< T, Compare >::is_empty(), Aleph::Fibonacci_Heap< T, Compare >::MAX_DEGREE, Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::num_nodes, Aleph::Fibonacci_Heap< T, Compare >::put_root_back(), and Aleph::Fibonacci_Heap< T, Compare >::take_root_out().
Referenced by demo_fibonacci_heap(), demo_max_heap(), demo_performance_comparison(), ArcFibonacciHeap< GT, Distance, Access_Heap_Node >::get_min_arc(), Aleph::Fibonacci_Heap< T, Compare >::pop(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), and verify_heap_property().
|
inlinenoexcept |
Returns the comparison functor that orders the heap.
Changing it while the heap has elements may leave the heap out of order.
Definition at line 1129 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::cmp.
Referenced by ArcFibonacciHeap< GT, Distance, Access_Heap_Node >::get_distance(), ArcFibonacciHeap< GT, Distance, Access_Heap_Node >::put_arc(), and TEST().
|
inline |
Returns the minimum element without removing it.
| std::underflow_error | if the heap is empty |
Definition at line 717 of file tpl_fibonacci_heap.H.
References ah_underflow_error_if, Aleph::Fibonacci_Heap< T, Compare >::Node::data, Aleph::Fibonacci_Heap< T, Compare >::is_empty(), and Aleph::Fibonacci_Heap< T, Compare >::min_node.
Referenced by demo_fibonacci_heap(), demo_max_heap(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and Aleph::Fibonacci_Heap< T, Compare >::top().
|
inlinenoexcept |
Returns a pointer to the minimum node.
Useful when you need the handle rather than just the value.
Definition at line 732 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::min_node.
Referenced by ArcFibonacciHeap< GT, Distance, Access_Heap_Node >::empty(), ArcFibonacciHeap< GT, Distance, Access_Heap_Node >::get_min_arc(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inline |
Inserts a new element (copy).
Creates a new node with a copy of val and adds it to the heap.
| val | The value to insert |
| anything | that the comparison throws. Then the heap is as it was. |
Definition at line 667 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::insert_new_node().
Referenced by demo_fibonacci_heap(), demo_max_heap(), demo_performance_comparison(), ArcFibonacciHeap< GT, Distance, Access_Heap_Node >::put_arc(), FibonacciHeapWithDataTest::SetUp(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inline |
Inserts a new element (move).
Creates a new node by moving val into it.
| val | The value to insert (will be moved) |
| anything | that the comparison throws. Then the heap is as it was. |
Definition at line 684 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::insert_new_node().
|
inlineprivate |
Definition at line 512 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::add_to_root_list(), and Aleph::Fibonacci_Heap< T, Compare >::num_nodes.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::emplace(), Aleph::Fibonacci_Heap< T, Compare >::insert(), and Aleph::Fibonacci_Heap< T, Compare >::insert().
|
inlinenoexcept |
Checks if the heap is empty.
Definition at line 1062 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::min_node.
Referenced by demo_fibonacci_heap(), demo_max_heap(), demo_performance_comparison(), Aleph::Fibonacci_Heap< T, Compare >::empty(), Aleph::Fibonacci_Heap< T, Compare >::extract_min(), Aleph::Fibonacci_Heap< T, Compare >::get_min(), ArcFibonacciHeap< GT, Distance, Access_Heap_Node >::get_min_arc(), ArcFibonacciHeap< GT, Distance, Access_Heap_Node >::is_empty(), Aleph::Fibonacci_Heap< T, Compare >::merge(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and verify_heap_property().
|
inline |
Returns the comparison functor.
Definition at line 1116 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::cmp.
Referenced by TEST().
|
inlinestaticprivate |
Links two trees of the same degree.
Makes y a child of x. Assumes both are roots and x has the smaller key.
| y | The node to become a child |
| x | The node to become the parent |
Definition at line 194 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::Node::child, Aleph::Fibonacci_Heap< T, Compare >::Node::degree, Aleph::Fibonacci_Heap< T, Compare >::Node::left, Aleph::Fibonacci_Heap< T, Compare >::Node::right, and y.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::consolidate().
|
inline |
Merges another heap into this one (rvalue version).
| other | Temporary heap whose contents will be transferred. |
merge(Fibonacci_Heap{...}). Definition at line 1050 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::merge().
|
inline |
Merges another heap into this one.
All nodes from other are transferred to this heap. The other heap becomes empty after this operation.
| other | The heap to merge (will be emptied) |
| anything | that the comparison throws. Then both heaps are as they were. |
Definition at line 1005 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::cmp, Aleph::Fibonacci_Heap< T, Compare >::Node::data, Aleph::Fibonacci_Heap< T, Compare >::is_empty(), Aleph::Fibonacci_Heap< T, Compare >::Node::left, Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::num_nodes, and Aleph::Fibonacci_Heap< T, Compare >::Node::right.
Referenced by demo_fibonacci_heap(), Aleph::Fibonacci_Heap< T, Compare >::merge(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
delete |
Copy assignment is disabled (use merge or manual copy)
|
inlinenoexcept |
Move assignment operator.
Clears this heap and transfers ownership from other.
| other | The heap to move from |
| anything | that the destructor of T, in clear(), or the move assignment of the comparison throws. If the comparison throws, this heap is empty and other keeps its elements. |
Definition at line 614 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::clear(), Aleph::Fibonacci_Heap< T, Compare >::cmp, Aleph::Fibonacci_Heap< T, Compare >::consolidate_array_, Aleph::Fibonacci_Heap< T, Compare >::min_node, and Aleph::Fibonacci_Heap< T, Compare >::num_nodes.
|
inline |
Definition at line 1101 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::extract_min().
|
inlineprivatenoexcept |
Undoes take_root_out() after a comparison threw.
Puts the node back in the root list, in which consolidate() leaves every tree when the comparison throws, and makes the minimum the node that was it before. A consolidation may have left that node under one of an equivalent key: then it is cut from it as decrease_key() cuts a node, so the one that loses it is marked, or cut too if it was. So the heap has the elements and the minimum that it had, though its trees may be others.
| z | The node that take_root_out() took out |
| min | The node that was the minimum, which may be z |
Definition at line 422 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::cascading_cut(), Aleph::Fibonacci_Heap< T, Compare >::cut(), Aleph::Fibonacci_Heap< T, Compare >::Node::left, min(), Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::Node::parent, and Aleph::Fibonacci_Heap< T, Compare >::Node::right.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::delete_node(), Aleph::Fibonacci_Heap< T, Compare >::extract_min(), and Aleph::Fibonacci_Heap< T, Compare >::update_key().
|
inlinenoexcept |
Returns the number of elements in the heap.
Definition at line 1074 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::num_nodes.
Referenced by demo_fibonacci_heap(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inlinenoexcept |
Swaps contents with another heap.
Exchanges all nodes between this heap and other in O(1) time.
| other | The heap to swap with |
| anything | that the swap of the comparisons throws: the swap that is_nothrow_swappable looks at, the one of Compare if it has one, else std::swap. Then the nodes stay where they were. |
Definition at line 643 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::cmp, Aleph::Fibonacci_Heap< T, Compare >::consolidate_array_, Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::num_nodes, and Aleph::Fibonacci_Heap< T, Compare >::swap().
Referenced by Aleph::Fibonacci_Heap< T, Compare >::swap(), TEST(), TEST(), TEST_F(), and TEST_F().
|
inlineprivatenoexcept |
Takes a root out of the root list, after putting its children in it as roots.
min_node is left on any other root, or null if there is none. The node keeps its data and is left without children.
| z | The root to take out |
Definition at line 372 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::Node::child, Aleph::Fibonacci_Heap< T, Compare >::Node::degree, Aleph::Fibonacci_Heap< T, Compare >::Node::left, Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::Node::parent, and Aleph::Fibonacci_Heap< T, Compare >::Node::right.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::delete_node(), Aleph::Fibonacci_Heap< T, Compare >::extract_min(), and Aleph::Fibonacci_Heap< T, Compare >::update_key().
|
inline |
Definition at line 1106 of file tpl_fibonacci_heap.H.
References Aleph::Fibonacci_Heap< T, Compare >::get_min().
|
inline |
Updates the key of a node (increase or decrease).
Unlike decrease_key, this method handles both increases and decreases. For increases, the node leaves its tree and goes back to the heap as a root with the new key, as if it were deleted and inserted again, but it is the same node: no node is allocated.
| x | Handle to the node |
| k | The new key value |
| std::invalid_argument | if x is nullptr |
| anything | that the comparison throws. Then x has its old key, and the heap has the elements that it had, the minimum among them, and every handle is valid; if the key increases, its trees may be linked otherwise. |
| anything | that the copy of the key throws. If the key increases, the copy is made before the heap changes, which is then as it was, and it is moved into the node at the end, or copied if the key has no move assignment: the above holds if that assignment does not throw. If the key decreases, see decrease_key(). |
| std::bad_alloc | if the key increases and there is no memory for the array of the consolidation, which is reserved once, before the heap changes. |
Definition at line 885 of file tpl_fibonacci_heap.H.
References ah_invalid_argument_if, Aleph::Fibonacci_Heap< T, Compare >::cascading_cut(), Aleph::Fibonacci_Heap< T, Compare >::cmp, Aleph::Fibonacci_Heap< T, Compare >::consolidate(), Aleph::Fibonacci_Heap< T, Compare >::consolidate_array_, Aleph::Fibonacci_Heap< T, Compare >::cut(), Aleph::Fibonacci_Heap< T, Compare >::Node::data, Aleph::Fibonacci_Heap< T, Compare >::decrease_key(), k, Aleph::Fibonacci_Heap< T, Compare >::MAX_DEGREE, min(), Aleph::Fibonacci_Heap< T, Compare >::min_node, Aleph::Fibonacci_Heap< T, Compare >::Node::parent, Aleph::Fibonacci_Heap< T, Compare >::put_root_back(), and Aleph::Fibonacci_Heap< T, Compare >::take_root_out().
|
related |
Swaps two Fibonacci heaps.
Definition at line 1141 of file tpl_fibonacci_heap.H.
|
private |
Comparison functor used to order nodes.
Definition at line 176 of file tpl_fibonacci_heap.H.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::add_to_root_list(), Aleph::Fibonacci_Heap< T, Compare >::consolidate(), Aleph::Fibonacci_Heap< T, Compare >::decrease_key(), Aleph::Fibonacci_Heap< T, Compare >::decrease_key(), Aleph::Fibonacci_Heap< T, Compare >::get_compare(), Aleph::Fibonacci_Heap< T, Compare >::key_comp(), Aleph::Fibonacci_Heap< T, Compare >::merge(), Aleph::Fibonacci_Heap< T, Compare >::operator=(), Aleph::Fibonacci_Heap< T, Compare >::swap(), and Aleph::Fibonacci_Heap< T, Compare >::update_key().
|
private |
Reusable scratch array for Fibonacci_Heap::consolidate().
Keeping the buffer as a member avoids heap allocations on every extract_min() call, which keeps amortized costs constant.
Definition at line 184 of file tpl_fibonacci_heap.H.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::consolidate(), Aleph::Fibonacci_Heap< T, Compare >::delete_node(), Aleph::Fibonacci_Heap< T, Compare >::extract_min(), Aleph::Fibonacci_Heap< T, Compare >::operator=(), Aleph::Fibonacci_Heap< T, Compare >::swap(), and Aleph::Fibonacci_Heap< T, Compare >::update_key().
|
staticconstexprprivate |
Maximum degree tracked during consolidation.
The degree of any Fibonacci heap root is bounded by log_phi(n). The value 128 comfortably covers heaps larger than 2^64 elements.
Definition at line 172 of file tpl_fibonacci_heap.H.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::consolidate(), Aleph::Fibonacci_Heap< T, Compare >::delete_node(), Aleph::Fibonacci_Heap< T, Compare >::extract_min(), and Aleph::Fibonacci_Heap< T, Compare >::update_key().
|
private |
Pointer to the current minimum root.
Definition at line 174 of file tpl_fibonacci_heap.H.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::add_to_root_list(), Aleph::Fibonacci_Heap< T, Compare >::clear(), Aleph::Fibonacci_Heap< T, Compare >::consolidate(), Aleph::Fibonacci_Heap< T, Compare >::cut(), Aleph::Fibonacci_Heap< T, Compare >::decrease_key(), Aleph::Fibonacci_Heap< T, Compare >::decrease_key(), Aleph::Fibonacci_Heap< T, Compare >::delete_node(), Aleph::Fibonacci_Heap< T, Compare >::extract_min(), Aleph::Fibonacci_Heap< T, Compare >::get_min(), Aleph::Fibonacci_Heap< T, Compare >::get_min_node(), Aleph::Fibonacci_Heap< T, Compare >::is_empty(), Aleph::Fibonacci_Heap< T, Compare >::merge(), Aleph::Fibonacci_Heap< T, Compare >::operator=(), Aleph::Fibonacci_Heap< T, Compare >::put_root_back(), Aleph::Fibonacci_Heap< T, Compare >::swap(), Aleph::Fibonacci_Heap< T, Compare >::take_root_out(), and Aleph::Fibonacci_Heap< T, Compare >::update_key().
|
private |
Number of elements stored in the heap.
Definition at line 175 of file tpl_fibonacci_heap.H.
Referenced by Aleph::Fibonacci_Heap< T, Compare >::clear(), Aleph::Fibonacci_Heap< T, Compare >::delete_node(), Aleph::Fibonacci_Heap< T, Compare >::extract_min(), Aleph::Fibonacci_Heap< T, Compare >::insert_new_node(), Aleph::Fibonacci_Heap< T, Compare >::merge(), Aleph::Fibonacci_Heap< T, Compare >::operator=(), Aleph::Fibonacci_Heap< T, Compare >::size(), and Aleph::Fibonacci_Heap< T, Compare >::swap().