Aleph-w 3.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 (Compare __cmp=Compare()) noexcept
 
virtual ~GenBinHeap () noexcept
 
Node * insert (Node *p) noexcept
 Inserts a node into a heap.
 
Node * getMin_ne () noexcept
 
Node * getMin ()
 Removes the node with the lowest priority from the heap.
 
Node * getMax ()
 
void update (Node *p) noexcept
 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
 

Protected Member Functions

virtual bool verify_heap (Node *p) const
 

Static Protected Member Functions

static Node * advance_left (Node *p) noexcept
 
static Node * advance_right (Node *p) noexcept
 

Protected Attributes

Compare cmp
 

Private Member Functions

void swap_with_parent (Node *p) noexcept
 
virtual void sift_up (Node *p) noexcept
 
virtual void sift_down (Node *p) noexcept
 
void swap_root_with_last () noexcept
 
Node * remove_last () noexcept
 
void replace_node (Node *node, Node *new_node) noexcept
 
template<class Operation >
bool preorder_traverse (Node *p, Operation op) const
 
template<class Op >
bool __level_traverse (Node *root, Op &operation) const
 

Static Private Member Functions

static bool is_in_list (Node *p) noexcept
 
static bool has_sibling (Node *p) noexcept
 
static void __postorder_delete (Node *p, Node *incomplete_node) noexcept
 
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
 
Node * head
 
Node *& root
 
Node * last
 
size_t num_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 instruments a node heap. This team doesn't is implemented by array, but with a binary tree. This provides the great advantage of being highly dynamic. The memory used is therefore proportional to the amount of nodes of the HEAP.

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 174 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 180 of file tpl_binHeap.H.

Constructor & Destructor Documentation

◆ GenBinHeap()

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

Definition at line 634 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 641 of file tpl_binHeap.H.

Member Function Documentation

◆ __for_each_in_inorder()

◆ __for_each_in_preorder()

◆ __level_traverse()

◆ __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

◆ advance_left()

◆ advance_right()

◆ 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

Definition at line 184 of file tpl_binHeap.H.

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

◆ getMax()

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

◆ getMin()

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 728 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::Huffman_Encoder_Engine::generate_huffman_tree(), ArcHeap< GT, Distance, Access_Heap_Node >::get_min_arc(), Aleph::GenBinHeap< NodeType, Key, Compare >::getMax(), Aleph::DynBinHeap< T, Compare >::getMin(), main(), 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 526 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

◆ 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

Definition at line 203 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 182 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

◆ preorder_traverse() [1/2]

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

◆ remove_last()

◆ 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

◆ sift_down()

◆ sift_up()

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

◆ swap_with_parent()

◆ top() [1/2]

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

Returns the node with the lowest priority according to the comparison criterion specified in the declaration.

Definition at line 817 of file tpl_binHeap.H.

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

Referenced by TimeoutQueue::next_event_time(), Aleph::DynBinHeap< T, Compare >::top(), and TimeoutQueue::triggerEvent().

◆ top() [2/2]

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

◆ 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
See also
insert()

Definition at line 750 of file tpl_binHeap.H.

References Aleph::GenBinHeap< NodeType, Key, Compare >::sift_down(), and Aleph::GenBinHeap< NodeType, Key, Compare >::sift_up().

Referenced by ArcHeap< GT, Distance, Access_Heap_Node >::put_arc(), Aleph::GenBinHeap< NodeType, Key, Compare >::remove(), Aleph::DynBinHeap< T, Compare >::update(), and Aleph::Huffman_Encoder_Engine::update_freq().

◆ verify_heap() [1/2]

◆ verify_heap() [2/2]

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

◆ num_nodes

◆ root


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