Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::GenBinHeap< NodeType, Key, Compare > Class Template Reference

Generic heap of nodes. More...

#include <tpl_binHeap.H>

Inheritance diagram for Aleph::GenBinHeap< NodeType, Key, Compare >:
[legend]
Collaboration diagram for Aleph::GenBinHeap< NodeType, Key, Compare >:
[legend]

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.
 

Detailed Description

template<template< class > class NodeType, typename Key, class Compare = Aleph::less<Key>>
requires StrictWeakOrder<Compare, Key>
class Aleph::GenBinHeap< NodeType, Key, Compare >

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.

Parameters
NodeTypethe type of node the HEAP uses; this will be with or without a virtual destroyer.
Keythe key that each node keeps.
Comparethe criterion of comparison between the keys of the Nodes.
See also
BinHeap BinHeapVtl DynBinHeap

Definition at line 306 of file tpl_binHeap.H.

Member Typedef Documentation

◆ Node

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
using Aleph::GenBinHeap< NodeType, Key, Compare >::Node = NodeType<Key>

Definition at line 320 of file tpl_binHeap.H.

Constructor & Destructor Documentation

◆ GenBinHeap() [1/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Aleph::GenBinHeap< NodeType, Key, Compare >::GenBinHeap ( )
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.

Exceptions
whatthe 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.

◆ GenBinHeap() [2/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Aleph::GenBinHeap< NodeType, Key, Compare >::GenBinHeap ( Compare  __cmp)
inlinenoexcept

Builds an empty heap with the comparison __cmp.

Parameters
[in]__cmpthe criterion of comparison, which the heap copies.
Exceptions
whatthe 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.

◆ ~GenBinHeap()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
virtual Aleph::GenBinHeap< NodeType, Key, Compare >::~GenBinHeap ( )
inlinevirtualnoexcept

Definition at line 940 of file tpl_binHeap.H.

Member Function Documentation

◆ __for_each_in_inorder()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
template<class Operation >
static void Aleph::GenBinHeap< NodeType, Key, Compare >::__for_each_in_inorder ( Node *  p,
Operation &  operation 
)
inlinestaticprivate

◆ __for_each_in_preorder()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
template<class Operation >
static void Aleph::GenBinHeap< NodeType, Key, Compare >::__for_each_in_preorder ( Node *  p,
Operation &  operation 
)
inlinestaticprivate

◆ __level_traverse()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
template<class Op >
bool Aleph::GenBinHeap< NodeType, Key, Compare >::__level_traverse ( Node *  root,
Op &  operation 
) const
inlineprivate

◆ __postorder_delete()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static void Aleph::GenBinHeap< NodeType, Key, Compare >::__postorder_delete ( Node *  p,
Node *  incomplete_node 
)
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().

◆ adopt_nodes()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::adopt_nodes ( )
inlineprivatenoexcept

◆ advance_left()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static Node * Aleph::GenBinHeap< NodeType, Key, Compare >::advance_left ( Node *  p)
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().

◆ advance_right()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static Node * Aleph::GenBinHeap< NodeType, Key, Compare >::advance_right ( Node *  p)
inlinestaticprotectednoexcept

◆ back_down()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::back_down ( Node *  p,
Node *  c 
)
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().

◆ back_under()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::back_under ( Node *  p,
Node *  pp 
)
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().

◆ back_up()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::back_up ( Node *  p,
Node *  pp 
)
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().

◆ for_each_in_inorder() [1/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
template<class Operation >
void Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_inorder ( Operation &&  operation = Operation()) const
inline

◆ for_each_in_inorder() [2/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
template<class Operation >
void Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_inorder ( Operation &  operation) const
inline

◆ for_each_in_preorder() [1/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
template<class Operation >
void Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_preorder ( Operation &&  operation = Operation()) const
inline

◆ for_each_in_preorder() [2/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
template<class Operation >
void Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_preorder ( Operation &  operation) const
inline

◆ get_compare()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Compare & Aleph::GenBinHeap< NodeType, Key, Compare >::get_compare ( )
inlinenoexcept

◆ getMax()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node * Aleph::GenBinHeap< NodeType, Key, Compare >::getMax ( )
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().

◆ getMin()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node * 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.

Returns
pointer to the removed node.
Exceptions
underflow_errorif the heap is empty.
anythingthat 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().

◆ getMin_ne()

◆ getRoot() [1/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node * Aleph::GenBinHeap< NodeType, Key, Compare >::getRoot ( ) const
inlinenoexcept

Definition at line 793 of file tpl_binHeap.H.

References Aleph::GenBinHeap< NodeType, Key, Compare >::root.

◆ getRoot() [2/2]

◆ has_sibling()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static bool Aleph::GenBinHeap< NodeType, Key, Compare >::has_sibling ( Node *  p)
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.

References RLINK, and ULINK.

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().

◆ insert()

◆ is_empty()

◆ is_in_list()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
static bool Aleph::GenBinHeap< NodeType, Key, Compare >::is_in_list ( Node *  p)
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().

◆ key_comp()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Compare & Aleph::GenBinHeap< NodeType, Key, Compare >::key_comp ( )
inlinenoexcept

Definition at line 322 of file tpl_binHeap.H.

References Aleph::GenBinHeap< NodeType, Key, Compare >::cmp.

◆ level_traverse()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
template<class Op >
bool Aleph::GenBinHeap< NodeType, Key, Compare >::level_traverse ( Op  operation = Op()) const
inline

◆ link_last()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::link_last ( Node *  p)
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().

◆ link_last_two()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::link_last_two ( Node *  first,
Node *  second 
)
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().

◆ preorder_traverse() [1/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
template<class Operation >
bool Aleph::GenBinHeap< NodeType, Key, Compare >::preorder_traverse ( Node *  p,
Operation  op 
) const
inlineprivate

◆ preorder_traverse() [2/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
template<class Operation >
bool Aleph::GenBinHeap< NodeType, Key, Compare >::preorder_traverse ( Operation  op) const
inline

◆ remove()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node * Aleph::GenBinHeap< NodeType, Key, Compare >::remove ( Node *  node)
inline

◆ remove_all_and_delete()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::remove_all_and_delete ( )
inlinenoexcept

◆ remove_last()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node * Aleph::GenBinHeap< NodeType, Key, Compare >::remove_last ( )
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().

◆ replace_node()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::replace_node ( Node *  node,
Node *  new_node 
)
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().

◆ sift_down()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
virtual void Aleph::GenBinHeap< NodeType, Key, Compare >::sift_down ( Node *  p)
inlineprivatevirtualnoexcept

◆ sift_up()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
virtual void Aleph::GenBinHeap< NodeType, Key, Compare >::sift_up ( Node *  p)
inlineprivatevirtualnoexcept

◆ size()

◆ swap()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::swap ( GenBinHeap< NodeType, Key, Compare > &  h)
inlinenoexcept

◆ swap_root_with_last()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::swap_root_with_last ( )
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().

◆ swap_with_parent()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::swap_with_parent ( Node *  p)
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().

◆ top() [1/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node * Aleph::GenBinHeap< NodeType, Key, Compare >::top ( )
inline

◆ top() [2/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node * Aleph::GenBinHeap< NodeType, Key, Compare >::top ( ) const
inline

◆ undo_extraction()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::undo_extraction ( Node *  moved,
Node *  old_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().

◆ undo_insert()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::undo_insert ( Node *  p)
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().

◆ undo_removal()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::undo_removal ( Node *  node,
Node *  p 
)
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().

◆ update()

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
void Aleph::GenBinHeap< NodeType, Key, Compare >::update ( Node *  p)
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.

Parameters
[in]ppointer to the node to update
Exceptions
anythingthat 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.
See also
insert()

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().

◆ verify_heap() [1/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
bool Aleph::GenBinHeap< NodeType, Key, Compare >::verify_heap ( ) const
inline

Checks the order of the heap.

Returns
true if no node has a key less than that of its parent.
Exceptions
anythingthat the comparison throws.
Note
It visits all the nodes: O(n).

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().

◆ verify_heap() [2/2]

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
virtual bool Aleph::GenBinHeap< NodeType, Key, Compare >::verify_heap ( Node *  p) const
inlineprotectedvirtual

Member Data Documentation

◆ cmp

◆ head

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node* Aleph::GenBinHeap< NodeType, Key, Compare >::head
private

◆ head_node

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
Node Aleph::GenBinHeap< NodeType, Key, Compare >::head_node
private

◆ last

◆ nothrow_cmp

template<template< class > class NodeType, typename Key , class Compare = Aleph::less<Key>>
constexpr bool Aleph::GenBinHeap< NodeType, Key, Compare >::nothrow_cmp
staticconstexprprotected
Initial value:
=
noexcept(static_cast<bool>(std::declval<Compare &>()(std::declval<Key &>(),
std::declval<Key &>())))

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().

◆ num_nodes

◆ root


The documentation for this class was generated from the following file: