|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Generic heap of nodes. More...
#include <tpl_binHeap.H>
Classes | |
| class | Iterator |
Public Types | |
| using | Node = NodeType< Key > |
Public Member Functions | |
| Compare & | key_comp () noexcept |
| Compare & | get_compare () noexcept |
| void | swap (GenBinHeap &h) noexcept |
| Node * | getRoot () noexcept |
| Node * | getRoot () const noexcept |
| template<class Operation > | |
| bool | preorder_traverse (Operation op) const |
| template<class Operation > | |
| void | for_each_in_preorder (Operation &operation) const |
| template<class Operation > | |
| void | for_each_in_preorder (Operation &&operation=Operation()) const |
| template<class Operation > | |
| void | for_each_in_inorder (Operation &operation) const |
| template<class Operation > | |
| void | for_each_in_inorder (Operation &&operation=Operation()) const |
| template<class Op > | |
| bool | level_traverse (Op operation=Op()) const |
| GenBinHeap () noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_default_constructible_v< Compare > and std::is_nothrow_constructible_v< Compare, Compare & >) | |
| Builds an empty heap with a comparison built by default. | |
| GenBinHeap (Compare __cmp) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_constructible_v< Compare, Compare & >) | |
Builds an empty heap with the comparison __cmp. | |
| virtual | ~GenBinHeap () noexcept |
| Node * | insert (Node *p) noexcept(nothrow_cmp) |
| Inserts a node into a heap. | |
| Node * | getMin_ne () noexcept(nothrow_cmp) |
| Removes the node with the lowest priority from a heap that is not empty. | |
| Node * | getMin () |
| Removes the node with the lowest priority from the heap. | |
| Node * | getMax () |
See getMin(); to use when the priority order is reversed. | |
| void | update (Node *p) noexcept(nothrow_cmp) |
| Updates the priority of a node contained in the heap. | |
| Node * | remove (Node *node) |
| Removes node from the heap. | |
| void | remove_all_and_delete () noexcept |
| Deletes all the nodes of the heap, invokes the destructors of the removed nodes, and frees all the memory. | |
| Node * | top () |
| Returns the node with the lowest priority according to the comparison criterion specified in the declaration. | |
| Node * | top () const |
| const size_t & | size () const noexcept |
| bool | is_empty () const noexcept |
| bool | verify_heap () const |
| Checks the order of the heap. | |
Protected Member Functions | |
| virtual bool | verify_heap (Node *p) const |
| Whether no node of the tree of root p has a key less than that of its parent. | |
Static Protected Member Functions | |
| static Node * | advance_left (Node *p) noexcept |
| The left child of p, or null if it has none. | |
| static Node * | advance_right (Node *p) noexcept |
| The right child of p, or null if it has none. | |
Protected Attributes | |
| Compare | cmp |
Static Protected Attributes | |
| static constexpr bool | nothrow_cmp |
Private Member Functions | |
| void | adopt_nodes () noexcept |
| void | swap_with_parent (Node *p) noexcept |
| Exchanges the node p, which is not the root, with its parent: each one takes the place of the other in the tree and in the list of the nodes that lack a child, and its flags. | |
| virtual void | sift_up (Node *p) noexcept(nothrow_cmp) |
| Takes p up while its key is less than that of its parent. | |
| virtual void | sift_down (Node *p) noexcept(nothrow_cmp) |
| Takes p down while its key is not less than that of its child with the least key. | |
| void | back_up (Node *p, Node *pp) noexcept |
| Takes back up the node p, which went down from under the node pp, until it is under it again. | |
| void | back_down (Node *p, Node *c) noexcept |
| Takes back down the node p, which went up, to the place of the node c, which is below it. | |
| void | back_under (Node *p, Node *pp) noexcept |
| Undoes what sift_down(p) and sift_up(p) did before the comparison threw: takes p, which is below or above its place, back under the node pp, which was over it. | |
| void | undo_insert (Node *p) noexcept |
| Undoes an insertion whose sift_up(p) threw: takes p back down to the last place, where it was linked, and unlinks it. | |
| void | undo_extraction (Node *moved, Node *old_root) noexcept |
| Undoes an extraction whose sift_down() threw: the node that took the place of the root goes back up to it, the old root is linked again as the last node, and the two exchange their places. | |
| void | undo_removal (Node *node, Node *p) noexcept |
| Undoes a removal whose update(p) threw, which left p at the place of node: node goes back to it, and p to the end. | |
| void | link_last_two (Node *first, Node *second) noexcept |
| Links again as the last nodes two nodes that were taken out: first, and then second. | |
| void | swap_root_with_last () noexcept |
| Exchanges the root with the last node: each one takes the place of the other in the tree, and the root that of the last node in the list of the nodes that lack a child. | |
| Node * | remove_last () noexcept |
| Takes the last node, which is not the root, out of the tree and of the list of the nodes that lack a child, and returns it. | |
| void | replace_node (Node *node, Node *new_node) noexcept |
| Puts new_node, which is out of the heap, at the place of node, which is not the last one: in the tree and, if node lacks a child, in the list of the nodes that lack one. | |
| template<class Operation > | |
| bool | preorder_traverse (Node *p, Operation op) const |
| template<class Op > | |
| bool | __level_traverse (Node *root, Op &operation) const |
| void | link_last (Node *p) noexcept |
| Links the node p as the last one of a heap that is not empty: after the last node in the list of the nodes that lack a child, and under the node that follows the last one in that list, which is the first one of the list. | |
Static Private Member Functions | |
| static bool | is_in_list (Node *p) noexcept |
| Whether p is in the list of the nodes that lack a child: it is a leaf, or its left child is its only one. | |
| static bool | has_sibling (Node *p) noexcept |
| Whether the parent of p, which is not the root, has another child. | |
| static void | __postorder_delete (Node *p, Node *incomplete_node) noexcept |
| Deletes the nodes of the tree of root p. | |
| template<class Operation > | |
| static void | __for_each_in_preorder (Node *p, Operation &operation) |
| template<class Operation > | |
| static void | __for_each_in_inorder (Node *p, Operation &operation) |
Private Attributes | |
| Node | head_node |
| The header node: the root is its right child. | |
| Node * | head |
| The address of the header node. | |
| Node *& | root |
| The node at the place 1; null in an empty heap. | |
| Node * | last |
| The node at the place n, where the list of the nodes that lack a child ends; the header node in an empty heap. | |
| size_t | num_nodes |
| The number n of nodes. | |
Generic heap of nodes.
The GenBinHeap class implements a heap of nodes. It is not on an array, but on a binary tree of linked nodes, which makes it highly dynamic: the memory used is proportional to the number of nodes of the heap.
The tree is complete, and the nodes that lack a child, which are those of its bottom, are also in a circular doubly linked list made with the links that they do not use for children. The node after the last one in that list is the parent of the next node to insert, and the node before it is the last one after a removal, so the heap finds both in O(1). The description of the file tpl_binHeap.H, in its section "Representation", has the whole of it.
This class is not intended for public use. Its purpose is to provide basic functionality to the BinHeap, BinHeapVtl, and DynBinHeap.
| NodeType | the type of node the HEAP uses; this will be with or without a virtual destroyer. |
| Key | the key that each node keeps. |
| Compare | the criterion of comparison between the keys of the Nodes. |
Definition at line 306 of file tpl_binHeap.H.
| using Aleph::GenBinHeap< NodeType, Key, Compare >::Node = NodeType<Key> |
Definition at line 320 of file tpl_binHeap.H.
|
inlinenoexcept |
Builds an empty heap with a comparison built by default.
It is a constructor apart from the one that takes the comparison, and not a default argument of that one: GCC and Clang do not count a default argument in the noexcept of the implicit default constructor of a heap that inherits these, as BinHeap, and what the construction of the comparison threw would end the program there.
| what | the default construction of the key of the header node or of the comparison, or the copy of the comparison, throws; nothing when they are noexcept. |
Definition at line 914 of file tpl_binHeap.H.
|
inlinenoexcept |
Builds an empty heap with the comparison __cmp.
| [in] | __cmp | the criterion of comparison, which the heap copies. |
| what | the default construction of the key of the header node or the copy of __cmp throws; nothing when both are noexcept. The copy is from a Compare that is not const, which a comparison may have apart from the one from a const one. |
Definition at line 931 of file tpl_binHeap.H.
|
inlinevirtualnoexcept |
Definition at line 940 of file tpl_binHeap.H.
|
inlinestaticprivate |
Definition at line 810 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::__for_each_in_inorder(), Aleph::GenBinHeap< NodeType, Key, Compare >::advance_left(), and Aleph::GenBinHeap< NodeType, Key, Compare >::advance_right().
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::__for_each_in_inorder().
|
inlinestaticprivate |
Definition at line 798 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::__for_each_in_preorder(), Aleph::GenBinHeap< NodeType, Key, Compare >::advance_left(), and Aleph::GenBinHeap< NodeType, Key, Compare >::advance_right().
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::__for_each_in_preorder().
|
inlineprivate |
Definition at line 865 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::advance_left(), Aleph::GenBinHeap< NodeType, Key, Compare >::advance_right(), Aleph::DynListQueue< T >::get(), Aleph::DynListQueue< T >::is_empty(), Aleph::DynListQueue< T >::put(), and Aleph::GenBinHeap< NodeType, Key, Compare >::root.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::level_traverse().
|
inlinestaticprivatenoexcept |
Deletes the nodes of the tree of root p.
incomplete_node is the node with a left child only, whose right link is of the list of the nodes that lack a child, or null if there is none
Definition at line 774 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::__postorder_delete(), IS_LEAF, LLINK, and RLINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::__postorder_delete(), and Aleph::GenBinHeap< NodeType, Key, Compare >::remove_all_and_delete().
|
inlineprivatenoexcept |
Definition at line 354 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::head, Aleph::GenBinHeap< NodeType, Key, Compare >::head_node, Aleph::GenBinHeap< NodeType, Key, Compare >::last, Aleph::GenBinHeap< NodeType, Key, Compare >::root, and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::swap().
|
inlinestaticprotectednoexcept |
The left child of p, or null if it has none.
Whatever walks the tree must take the children from here and from advance_right(): in the nodes that lack a child, the links LLINK and RLINK are those of their list, and never null
Definition at line 1230 of file tpl_binHeap.H.
References IS_LEAF, and LLINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::__for_each_in_inorder(), Aleph::GenBinHeap< NodeType, Key, Compare >::__for_each_in_preorder(), Aleph::GenBinHeap< NodeType, Key, Compare >::__level_traverse(), Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::next_ne(), Aleph::GenBinHeap< NodeType, Key, Compare >::preorder_traverse(), and Aleph::GenBinHeap< NodeType, Key, Compare >::verify_heap().
|
inlinestaticprotectednoexcept |
The right child of p, or null if it has none.
A node with a left child only has in RLINK its next node of the list of the nodes that lack a child
Definition at line 1241 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::has_sibling(), IS_LEAF, LLINK, and RLINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::__for_each_in_inorder(), Aleph::GenBinHeap< NodeType, Key, Compare >::__for_each_in_preorder(), Aleph::GenBinHeap< NodeType, Key, Compare >::__level_traverse(), Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::next_ne(), Aleph::GenBinHeap< NodeType, Key, Compare >::preorder_traverse(), Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::reset_last(), and Aleph::GenBinHeap< NodeType, Key, Compare >::verify_heap().
|
inlineprivatenoexcept |
Takes back down the node p, which went up, to the place of the node c, which is below it.
The nodes that p passed are those of the way from c up to p: p exchanges with each one of them, from the top, so it goes over the way once
Definition at line 556 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::back_down(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap_with_parent(), and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::back_down(), Aleph::GenBinHeap< NodeType, Key, Compare >::back_under(), and Aleph::GenBinHeap< NodeType, Key, Compare >::undo_insert().
|
inlineprivatenoexcept |
Undoes what sift_down(p) and sift_up(p) did before the comparison threw: takes p, which is below or above its place, back under the node pp, which was over it.
Definition at line 566 of file tpl_binHeap.H.
References Aleph::and, Aleph::GenBinHeap< NodeType, Key, Compare >::back_down(), Aleph::GenBinHeap< NodeType, Key, Compare >::back_up(), Aleph::GenBinHeap< NodeType, Key, Compare >::head, and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::update().
|
inlineprivatenoexcept |
Takes back up the node p, which went down from under the node pp, until it is under it again.
Definition at line 546 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::swap_with_parent(), and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::back_under(), and Aleph::GenBinHeap< NodeType, Key, Compare >::undo_extraction().
|
inline |
Definition at line 858 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_inorder().
|
inline |
Definition at line 852 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::getRoot().
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_inorder().
|
inline |
Definition at line 846 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_preorder().
|
inline |
Definition at line 840 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::getRoot().
Referenced by Aleph::DynBinHeap< T, Compare >::copy(), ArcHeap< GT, Distance, Access_Heap_Node >::empty(), and Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_preorder().
|
inlinenoexcept |
Definition at line 324 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::cmp.
Referenced by ArcHeap< GT, Distance, Access_Heap_Node >::get_distance(), and ArcHeap< GT, Distance, Access_Heap_Node >::put_arc().
|
inline |
See getMin(); to use when the priority order is reversed.
Definition at line 1083 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::getMin().
|
inline |
Removes the node with the lowest priority from the heap.
getMIn() extracts from this heap the node that holds the lowest priority value according to the comparison criterion defined in the declaration.
| underflow_error | if the heap is empty. |
| anything | that the comparison throws, as getMin_ne() does. |
Definition at line 1076 of file tpl_binHeap.H.
References ah_underflow_error_if, Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), and Aleph::GenBinHeap< NodeType, Key, Compare >::root.
Referenced by TimeoutQueue::clear_all(), Aleph::GenBinHeap< NodeType, Key, Compare >::getMax(), Aleph::DynBinHeap< T, Compare >::getMin(), main(), Aleph::Huffman_Encoder_Engine::merge_two_nodes(), TEST(), and TimeoutQueue::triggerEvent().
|
inlinenoexcept |
Removes the node with the lowest priority from a heap that is not empty.
| anything | that the comparison throws. Then the node is in the heap, which is as it was. |
Definition at line 1031 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::head_node, Aleph::GenBinHeap< NodeType, Key, Compare >::last, Aleph::GenBinHeap< NodeType, Key, Compare >::nothrow_cmp, Aleph::GenBinHeap< NodeType, Key, Compare >::num_nodes, Aleph::GenBinHeap< NodeType, Key, Compare >::remove_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::root, Aleph::GenBinHeap< NodeType, Key, Compare >::sift_down(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap_root_with_last(), and Aleph::GenBinHeap< NodeType, Key, Compare >::undo_extraction().
Referenced by Aleph::Huffman_Encoder_Engine::clear_build_state(), Aleph::Huffman_Encoder_Engine::generate_huffman_tree(), ArcHeap< GT, Distance, Access_Heap_Node >::get_min_arc(), Aleph::GenBinHeap< NodeType, Key, Compare >::getMin(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove(), and Aleph::Huffman_Encoder_Engine::undo_generation().
|
inlinenoexcept |
Definition at line 793 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::root.
|
inlinenoexcept |
Definition at line 791 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::root.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_inorder(), Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_preorder(), Aleph::GenBinHeap< NodeType, Key, Compare >::level_traverse(), and Aleph::GenBinHeap< NodeType, Key, Compare >::preorder_traverse().
|
inlinestaticprivatenoexcept |
Whether the parent of p, which is not the root, has another child.
It does not when the next node of p in the list is that parent, which only happens to the last node, if it is a left child
Definition at line 375 of file tpl_binHeap.H.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::advance_right(), Aleph::GenBinHeap< NodeType, Key, Compare >::sift_down(), and Aleph::GenBinHeap< NodeType, Key, Compare >::swap_with_parent().
|
inlinenoexcept |
Inserts a node into a heap.
insert(p) inserts node p into this heap.
| [in] | p | the node to insert. |
| anything | that the comparison throws. Then p is out of the heap, which is as it was, and can be inserted again. |
Definition at line 989 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::head, IS_LEAF, IS_LEFT, Aleph::GenBinHeap< NodeType, Key, Compare >::last, Aleph::GenBinHeap< NodeType, Key, Compare >::link_last(), LLINK, Aleph::GenBinHeap< NodeType, Key, Compare >::nothrow_cmp, Aleph::GenBinHeap< NodeType, Key, Compare >::num_nodes, RLINK, Aleph::GenBinHeap< NodeType, Key, Compare >::root, Aleph::GenBinHeap< NodeType, Key, Compare >::sift_up(), ULINK, and Aleph::GenBinHeap< NodeType, Key, Compare >::undo_insert().
Referenced by Aleph::DynBinHeap< T, Compare >::__insert(), Aleph::Huffman_Encoder_Engine::insert_symbol_node(), main(), Aleph::Huffman_Encoder_Engine::merge_two_nodes(), ArcHeap< GT, Distance, Access_Heap_Node >::put_arc(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove(), TimeoutQueue::reschedule_event(), TimeoutQueue::schedule_event(), TEST(), TEST(), TEST(), TEST(), and Aleph::Huffman_Encoder_Engine::undo_generation().
|
inlinenoexcept |
Definition at line 1223 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::size().
Referenced by Aleph::Huffman_Encoder_Engine::clear_build_state(), demo_binary_heap(), demo_event_simulation(), demo_max_heap(), demo_performance_comparison(), Aleph::Huffman_Encoder_Engine::generate_huffman_tree(), Aleph::Prim_Min_Spanning_Tree< GT, Distance, SA >::min_spanning_tree(), Aleph::Gen_MultiPolynomial< Coefficient, MonomOrder >::pop_best_pair(), Aleph::DynBinHeap< T, Compare >::remove(), Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::reset_first(), Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::reset_last(), Aleph::VisvalingamWhyattSimplification::simplify_open_array(), Aleph::VisvalingamWhyattSimplification::simplify_polygon(), Aleph::ssp_shortest_path(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and Aleph::Huffman_Encoder_Engine::undo_generation().
|
inlinestaticprivatenoexcept |
Whether p is in the list of the nodes that lack a child: it is a leaf, or its left child is its only one.
Definition at line 364 of file tpl_binHeap.H.
References IS_LEAF, LLINK, RLINK, and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::swap_with_parent().
|
inlinenoexcept |
Definition at line 322 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::cmp.
|
inline |
Definition at line 896 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::__level_traverse(), and Aleph::GenBinHeap< NodeType, Key, Compare >::getRoot().
|
inlineprivatenoexcept |
Links the node p as the last one of a heap that is not empty: after the last node in the list of the nodes that lack a child, and under the node that follows the last one in that list, which is the first one of the list.
remove_last() undoes it
Definition at line 949 of file tpl_binHeap.H.
References IS_LEAF, IS_LEFT, Aleph::GenBinHeap< NodeType, Key, Compare >::last, LLINK, Aleph::GenBinHeap< NodeType, Key, Compare >::num_nodes, RLINK, and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::insert(), Aleph::GenBinHeap< NodeType, Key, Compare >::link_last_two(), Aleph::GenBinHeap< NodeType, Key, Compare >::undo_extraction(), and Aleph::GenBinHeap< NodeType, Key, Compare >::undo_removal().
|
inlineprivatenoexcept |
Links again as the last nodes two nodes that were taken out: first, and then second.
Definition at line 607 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::link_last().
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::remove().
|
inlineprivate |
Definition at line 821 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::advance_left(), Aleph::GenBinHeap< NodeType, Key, Compare >::advance_right(), and Aleph::GenBinHeap< NodeType, Key, Compare >::preorder_traverse().
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::preorder_traverse(), Aleph::GenBinHeap< NodeType, Key, Compare >::preorder_traverse(), Aleph::DynBinHeap< T, Compare >::traverse(), and Aleph::DynBinHeap< T, Compare >::traverse().
|
inline |
Definition at line 834 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::getRoot(), and Aleph::GenBinHeap< NodeType, Key, Compare >::preorder_traverse().
|
inline |
Removes node from the heap.
remove(node) removes node from this heap.
| [in] | node | pointer to the node to remove. |
| underflow_error | if the heap is empty |
| anything | that the comparison throws. Then node is in the heap, which is as it was. |
Definition at line 1135 of file tpl_binHeap.H.
References ah_underflow_error_if, Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), Aleph::GenBinHeap< NodeType, Key, Compare >::insert(), Aleph::GenBinHeap< NodeType, Key, Compare >::last, Aleph::GenBinHeap< NodeType, Key, Compare >::link_last_two(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::replace_node(), Aleph::GenBinHeap< NodeType, Key, Compare >::root, Aleph::GenBinHeap< NodeType, Key, Compare >::undo_removal(), and Aleph::GenBinHeap< NodeType, Key, Compare >::update().
Referenced by TimeoutQueue::cancel_by_id(), TimeoutQueue::cancel_delete_event(), TimeoutQueue::cancel_event(), main(), Aleph::DynBinHeap< T, Compare >::remove(), TimeoutQueue::reschedule_event(), and TEST().
|
inlinenoexcept |
Deletes all the nodes of the heap, invokes the destructors of the removed nodes, and frees all the memory.
Definition at line 1179 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::__postorder_delete(), Aleph::GenBinHeap< NodeType, Key, Compare >::head_node, IS_LEFT, Aleph::GenBinHeap< NodeType, Key, Compare >::last, Aleph::GenBinHeap< NodeType, Key, Compare >::num_nodes, Aleph::GenBinHeap< NodeType, Key, Compare >::remove_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::root, and ULINK.
Referenced by ArcHeap< GT, Distance, Access_Heap_Node >::empty(), Aleph::DynBinHeap< T, Compare >::empty(), and main().
|
inlineprivatenoexcept |
Takes the last node, which is not the root, out of the tree and of the list of the nodes that lack a child, and returns it.
Its previous node in the list is the new last node, and its parent is the first node of the list from then on: it stays so if the last node was its only child, and it enters the list if it had two
Definition at line 689 of file tpl_binHeap.H.
References Aleph::and, IS_LEAF, IS_LEFT, Aleph::GenBinHeap< NodeType, Key, Compare >::last, LLINK, Aleph::GenBinHeap< NodeType, Key, Compare >::num_nodes, RLINK, Aleph::GenBinHeap< NodeType, Key, Compare >::root, and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove_all_and_delete(), and Aleph::GenBinHeap< NodeType, Key, Compare >::undo_insert().
|
inlineprivatenoexcept |
Puts new_node, which is out of the heap, at the place of node, which is not the last one: in the tree and, if node lacks a child, in the list of the nodes that lack one.
The links of node are left as they were
Definition at line 721 of file tpl_binHeap.H.
References CTRL_BITS, IS_LEAF, IS_LEFT, Aleph::GenBinHeap< NodeType, Key, Compare >::last, LLINK, RLINK, and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::remove(), and Aleph::GenBinHeap< NodeType, Key, Compare >::undo_removal().
|
inlineprivatevirtualnoexcept |
Takes p down while its key is not less than that of its child with the least key.
Definition at line 528 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::cmp, Aleph::GenBinHeap< NodeType, Key, Compare >::has_sibling(), IS_LEAF, KEY, LLINK, RLINK, and Aleph::GenBinHeap< NodeType, Key, Compare >::swap_with_parent().
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), and Aleph::GenBinHeap< NodeType, Key, Compare >::update().
|
inlineprivatevirtualnoexcept |
Takes p up while its key is less than that of its parent.
Definition at line 520 of file tpl_binHeap.H.
References Aleph::and, Aleph::GenBinHeap< NodeType, Key, Compare >::cmp, KEY, Aleph::GenBinHeap< NodeType, Key, Compare >::root, Aleph::GenBinHeap< NodeType, Key, Compare >::swap_with_parent(), and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::insert(), and Aleph::GenBinHeap< NodeType, Key, Compare >::update().
|
inlinenoexcept |
Definition at line 1221 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::num_nodes.
Referenced by TimeoutQueue::cancel_by_id(), TimeoutQueue::cancel_delete_event(), TimeoutQueue::cancel_event(), TimeoutQueue::clear_all(), demo_binary_heap(), Aleph::Huffman_Encoder_Engine::generate_huffman_tree(), TimeoutQueue::is_empty(), Aleph::GenBinHeap< NodeType, Key, Compare >::is_empty(), main(), TimeoutQueue::next_event_time(), TimeoutQueue::size(), TEST(), TEST(), TEST(), TEST(), TEST(), TimeoutQueue::triggerEvent(), and TimeoutQueue::wait_until_empty().
|
inlinenoexcept |
Definition at line 340 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::adopt_nodes(), Aleph::GenBinHeap< NodeType, Key, Compare >::cmp, h, Aleph::GenBinHeap< NodeType, Key, Compare >::last, Aleph::GenBinHeap< NodeType, Key, Compare >::num_nodes, and Aleph::GenBinHeap< NodeType, Key, Compare >::root.
Referenced by TEST().
|
inlineprivatenoexcept |
Exchanges the root with the last node: each one takes the place of the other in the tree, and the root that of the last node in the list of the nodes that lack a child.
Definition at line 616 of file tpl_binHeap.H.
References Aleph::and, CTRL_BITS, Aleph::GenBinHeap< NodeType, Key, Compare >::head, IS_LEAF, Aleph::GenBinHeap< NodeType, Key, Compare >::last, LLINK, NEXT, Aleph::GenBinHeap< NodeType, Key, Compare >::num_nodes, PREV, RLINK, Aleph::GenBinHeap< NodeType, Key, Compare >::root, and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), and Aleph::GenBinHeap< NodeType, Key, Compare >::undo_extraction().
|
inlineprivatenoexcept |
Exchanges the node p, which is not the root, with its parent: each one takes the place of the other in the tree and in the list of the nodes that lack a child, and its flags.
The heaps of 2 and of 3 nodes apart, the cases are three: neither node is in the list, only p is, or both are, which is when p is the last node and the only child of its parent
Definition at line 386 of file tpl_binHeap.H.
References CTRL_BITS, Aleph::GenBinHeap< NodeType, Key, Compare >::has_sibling(), Aleph::GenBinHeap< NodeType, Key, Compare >::is_in_list(), IS_LEAF, Aleph::GenBinHeap< NodeType, Key, Compare >::last, LLINK, Aleph::GenBinHeap< NodeType, Key, Compare >::num_nodes, RLINK, Aleph::GenBinHeap< NodeType, Key, Compare >::root, and ULINK.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::back_down(), Aleph::GenBinHeap< NodeType, Key, Compare >::back_up(), Aleph::GenBinHeap< NodeType, Key, Compare >::sift_down(), and Aleph::GenBinHeap< NodeType, Key, Compare >::sift_up().
|
inline |
Returns the node with the lowest priority according to the comparison criterion specified in the declaration.
Definition at line 1207 of file tpl_binHeap.H.
References ah_underflow_error_if, and Aleph::GenBinHeap< NodeType, Key, Compare >::root.
Referenced by Aleph::Huffman_Encoder_Engine::generate_huffman_tree(), ArcHeap< GT, Distance, Access_Heap_Node >::get_min_arc(), TimeoutQueue::next_event_time(), TEST(), Aleph::DynBinHeap< T, Compare >::top(), and TimeoutQueue::triggerEvent().
|
inline |
Definition at line 1214 of file tpl_binHeap.H.
References ah_underflow_error_if, and Aleph::GenBinHeap< NodeType, Key, Compare >::root.
|
inlineprivatenoexcept |
Undoes an extraction whose sift_down() threw: the node that took the place of the root goes back up to it, the old root is linked again as the last node, and the two exchange their places.
Definition at line 589 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::back_up(), Aleph::GenBinHeap< NodeType, Key, Compare >::head, Aleph::GenBinHeap< NodeType, Key, Compare >::link_last(), and Aleph::GenBinHeap< NodeType, Key, Compare >::swap_root_with_last().
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne().
|
inlineprivatenoexcept |
Undoes an insertion whose sift_up(p) threw: takes p back down to the last place, where it was linked, and unlinks it.
Definition at line 579 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::back_down(), Aleph::GenBinHeap< NodeType, Key, Compare >::last, and Aleph::GenBinHeap< NodeType, Key, Compare >::remove_last().
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::insert().
|
inlineprivatenoexcept |
Undoes a removal whose update(p) threw, which left p at the place of node: node goes back to it, and p to the end.
Definition at line 598 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::link_last(), and Aleph::GenBinHeap< NodeType, Key, Compare >::replace_node().
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::remove().
|
inlinenoexcept |
Updates the priority of a node contained in the heap.
update(p) takes a node of the heap whose priority has been modified and updates its priority within the heap. The idea is that if for some reason a priority must be modified, then the extraction order can be updated.
| [in] | p | pointer to the node to update |
| anything | that the comparison throws. Then no node has moved: the heap is as it was before the call, with p at its place, where its new priority may be out of order. |
Definition at line 1101 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::back_under(), Aleph::GenBinHeap< NodeType, Key, Compare >::nothrow_cmp, Aleph::GenBinHeap< NodeType, Key, Compare >::sift_down(), Aleph::GenBinHeap< NodeType, Key, Compare >::sift_up(), and ULINK.
Referenced by ArcHeap< GT, Distance, Access_Heap_Node >::put_arc(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove(), TEST(), Aleph::DynBinHeap< T, Compare >::update(), and Aleph::Huffman_Encoder_Engine::update_freq().
|
inline |
Checks the order of the heap.
| anything | that the comparison throws. |
Definition at line 1283 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::root, and Aleph::GenBinHeap< NodeType, Key, Compare >::verify_heap().
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::verify_heap(), and Aleph::GenBinHeap< NodeType, Key, Compare >::verify_heap().
|
inlineprotectedvirtual |
Whether no node of the tree of root p has a key less than that of its parent.
Definition at line 1254 of file tpl_binHeap.H.
References Aleph::GenBinHeap< NodeType, Key, Compare >::advance_left(), Aleph::GenBinHeap< NodeType, Key, Compare >::advance_right(), Aleph::and, Aleph::GenBinHeap< NodeType, Key, Compare >::cmp, IS_LEAF, KEY, and Aleph::GenBinHeap< NodeType, Key, Compare >::verify_heap().
|
protected |
Definition at line 309 of file tpl_binHeap.H.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::get_compare(), Aleph::GenBinHeap< NodeType, Key, Compare >::key_comp(), Aleph::GenBinHeap< NodeType, Key, Compare >::sift_down(), Aleph::GenBinHeap< NodeType, Key, Compare >::sift_up(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap(), and Aleph::GenBinHeap< NodeType, Key, Compare >::verify_heap().
|
private |
The address of the header node.
Definition at line 330 of file tpl_binHeap.H.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::adopt_nodes(), Aleph::GenBinHeap< NodeType, Key, Compare >::back_under(), Aleph::GenBinHeap< NodeType, Key, Compare >::insert(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap_root_with_last(), and Aleph::GenBinHeap< NodeType, Key, Compare >::undo_extraction().
|
private |
The header node: the root is its right child.
Definition at line 328 of file tpl_binHeap.H.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::adopt_nodes(), Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), and Aleph::GenBinHeap< NodeType, Key, Compare >::remove_all_and_delete().
|
private |
The node at the place n, where the list of the nodes that lack a child ends; the header node in an empty heap.
Definition at line 335 of file tpl_binHeap.H.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::adopt_nodes(), Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), Aleph::GenBinHeap< NodeType, Key, Compare >::insert(), Aleph::GenBinHeap< NodeType, Key, Compare >::link_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove_all_and_delete(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::replace_node(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap_root_with_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap_with_parent(), and Aleph::GenBinHeap< NodeType, Key, Compare >::undo_insert().
|
staticconstexprprotected |
Definition at line 315 of file tpl_binHeap.H.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), Aleph::GenBinHeap< NodeType, Key, Compare >::insert(), and Aleph::GenBinHeap< NodeType, Key, Compare >::update().
|
private |
The number n of nodes.
Definition at line 337 of file tpl_binHeap.H.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::end(), Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), Aleph::GenBinHeap< NodeType, Key, Compare >::insert(), Aleph::GenBinHeap< NodeType, Key, Compare >::link_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove_all_and_delete(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::reset_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::size(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap_root_with_last(), and Aleph::GenBinHeap< NodeType, Key, Compare >::swap_with_parent().
|
private |
The node at the place 1; null in an empty heap.
Definition at line 332 of file tpl_binHeap.H.
Referenced by Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::Iterator(), Aleph::GenBinHeap< NodeType, Key, Compare >::__level_traverse(), Aleph::GenBinHeap< NodeType, Key, Compare >::adopt_nodes(), Aleph::GenBinHeap< NodeType, Key, Compare >::getMin(), Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), Aleph::GenBinHeap< NodeType, Key, Compare >::getRoot(), Aleph::GenBinHeap< NodeType, Key, Compare >::getRoot(), Aleph::GenBinHeap< NodeType, Key, Compare >::insert(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove_all_and_delete(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::reset_first(), Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::reset_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::sift_up(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap_root_with_last(), Aleph::GenBinHeap< NodeType, Key, Compare >::swap_with_parent(), Aleph::GenBinHeap< NodeType, Key, Compare >::top(), Aleph::GenBinHeap< NodeType, Key, Compare >::top(), and Aleph::GenBinHeap< NodeType, Key, Compare >::verify_heap().