Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ArcHeap< GT, Distance, Access_Heap_Node > Class Template Reference

#include <archeap.H>

Inheritance diagram for ArcHeap< GT, Distance, Access_Heap_Node >:
[legend]
Collaboration diagram for ArcHeap< GT, Distance, Access_Heap_Node >:
[legend]

Public Types

typedef BinHeap< typename GT::Arc *, Distance_Compare< GT, Distance > > Heap
 
typedef Heap::Node Node
 
using handle_type = Node *
 
- Public Types inherited from Aleph::BinHeap< GT::Arc *, Distance_Compare< GT, Distance > >
using Node = BinHeapNode< GT::Arc * >
 The heap's node type.
 
- Public Types inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
using Node = NodeType< Key >
 

Public Member Functions

Distance & get_distance ()
 Return the distance functor of the comparison that orders the arcs of this heap and chooses between two arcs to the same node.
 
 ArcHeap (Distance __dist=Distance(), Access_Heap_Node acc=Access_Heap_Node())
 Construct an empty arc heap with the given distance functor and heap-node access policy.
 
 ArcHeap (const ArcHeap &)=delete
 Copying is disabled (heap manages internal node memory)
 
ArcHeap & operator= (const ArcHeap &)=delete
 
 ArcHeap (ArcHeap &&other) noexcept
 Move construction transfers ownership of heap nodes and the distance.
 
ArcHeap & operator= (ArcHeap &&other) noexcept
 Move assignment transfers ownership of heap nodes and the distance, after emptying this heap as empty() does.
 
void put_arc (typename GT::Arc *arc, typename GT::Node *tgt)
 Insert or update an arc associated with a target node, keeping the smallest-distance arc per node in the heap.
 
GT::Arc * get_min_arc ()
 Extract the arc with minimum distance from the heap and clear its node-to-heap mapping.
 
void empty ()
 Remove all heap nodes and delete their memory, after clearing the handles that the access functor keeps for them, so that their nodes can be put in a heap again.
 
void clear ()
 Empties the container.
 
 ~ArcHeap ()
 Destructor. Clears all remaining heap nodes, as empty() does.
 
- Public Member Functions inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
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.
 

Private Member Functions

handle_type & handle_of (Node *heap_node)
 

Private Attributes

Access_Heap_Node access_node
 

Additional Inherited Members

- Protected Member Functions inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
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 inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
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 inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
Compare cmp
 
- Static Protected Attributes inherited from Aleph::GenBinHeap< NodeType, Key, Compare >
static constexpr bool nothrow_cmp
 

Detailed Description

template<class GT, class Distance, class Access_Heap_Node>
class ArcHeap< GT, Distance, Access_Heap_Node >

Definition at line 56 of file archeap.H.

Member Typedef Documentation

◆ handle_type

template<class GT , class Distance , class Access_Heap_Node >
using ArcHeap< GT, Distance, Access_Heap_Node >::handle_type = Node *

Definition at line 107 of file archeap.H.

◆ Heap

template<class GT , class Distance , class Access_Heap_Node >
typedef BinHeap<typename GT::Arc *, Distance_Compare<GT, Distance> > ArcHeap< GT, Distance, Access_Heap_Node >::Heap

Definition at line 103 of file archeap.H.

◆ Node

template<class GT , class Distance , class Access_Heap_Node >
typedef Heap::Node ArcHeap< GT, Distance, Access_Heap_Node >::Node

Definition at line 105 of file archeap.H.

Constructor & Destructor Documentation

◆ ArcHeap() [1/3]

template<class GT , class Distance , class Access_Heap_Node >
ArcHeap< GT, Distance, Access_Heap_Node >::ArcHeap ( Distance  __dist = Distance(),
Access_Heap_Node  acc = Access_Heap_Node() 
)
inline

Construct an empty arc heap with the given distance functor and heap-node access policy.

Definition at line 69 of file archeap.H.

◆ ArcHeap() [2/3]

template<class GT , class Distance , class Access_Heap_Node >
ArcHeap< GT, Distance, Access_Heap_Node >::ArcHeap ( const ArcHeap< GT, Distance, Access_Heap_Node > &  )
delete

Copying is disabled (heap manages internal node memory)

◆ ArcHeap() [3/3]

template<class GT , class Distance , class Access_Heap_Node >
ArcHeap< GT, Distance, Access_Heap_Node >::ArcHeap ( ArcHeap< GT, Distance, Access_Heap_Node > &&  other)
inlinenoexcept

Move construction transfers ownership of heap nodes and the distance.

(The base heap cannot be moved: it points to its own header, so it is swapped, with its comparison.)

Definition at line 83 of file archeap.H.

References Aleph::swap().

◆ ~ArcHeap()

template<class GT , class Distance , class Access_Heap_Node >
ArcHeap< GT, Distance, Access_Heap_Node >::~ArcHeap ( )
inline

Destructor. Clears all remaining heap nodes, as empty() does.

Definition at line 205 of file archeap.H.

References ArcHeap< GT, Distance, Access_Heap_Node >::empty().

Member Function Documentation

◆ clear()

template<class GT , class Distance , class Access_Heap_Node >
void ArcHeap< GT, Distance, Access_Heap_Node >::clear ( )
inline

Empties the container.

Exceptions
none
See also
empty()

Definition at line 202 of file archeap.H.

References ArcHeap< GT, Distance, Access_Heap_Node >::empty().

◆ empty()

template<class GT , class Distance , class Access_Heap_Node >
void ArcHeap< GT, Distance, Access_Heap_Node >::empty ( )
inline

Remove all heap nodes and delete their memory, after clearing the handles that the access functor keeps for them, so that their nodes can be put in a heap again.

No arc is compared. The storage of the handles must still be alive, and the access functor, called for both nodes of each arc, must not throw: the destructor and the move assignment, which do not throw, empty the heap too. With the handles in a map, operator[] of std::unordered_map, for one, inserts the nodes that it does not find, and may throw std::bad_alloc.

Definition at line 191 of file archeap.H.

References Aleph::GenBinHeap< NodeType, Key, Compare >::for_each_in_preorder(), ArcHeap< GT, Distance, Access_Heap_Node >::handle_of(), and Aleph::GenBinHeap< NodeType, Key, Compare >::remove_all_and_delete().

Referenced by ArcHeap< GT, Distance, Access_Heap_Node >::~ArcHeap(), ArcHeap< GT, Distance, Access_Heap_Node >::clear(), and ArcHeap< GT, Distance, Access_Heap_Node >::operator=().

◆ get_distance()

template<class GT , class Distance , class Access_Heap_Node >
Distance & ArcHeap< GT, Distance, Access_Heap_Node >::get_distance ( )
inline

Return the distance functor of the comparison that orders the arcs of this heap and chooses between two arcs to the same node.

Changing it while the heap has arcs may leave the heap out of order.

Definition at line 65 of file archeap.H.

References Aleph::GenBinHeap< NodeType, Key, Compare >::get_compare().

◆ get_min_arc()

template<class GT , class Distance , class Access_Heap_Node >
GT::Arc * ArcHeap< GT, Distance, Access_Heap_Node >::get_min_arc ( )
inline

Extract the arc with minimum distance from the heap and clear its node-to-heap mapping.

If the distance throws, the heap is as it was, with the arc in it and its mapping.

Definition at line 171 of file archeap.H.

References Aleph::BinHeapNode< Key >::get_key(), Aleph::GenBinHeap< NodeType, Key, Compare >::getMin_ne(), ArcHeap< GT, Distance, Access_Heap_Node >::handle_of(), and Aleph::GenBinHeap< NodeType, Key, Compare >::top().

Referenced by Aleph::Prim_Min_Spanning_Tree< GT, Distance, SA >::min_spanning_tree(), and TEST().

◆ handle_of()

◆ operator=() [1/2]

template<class GT , class Distance , class Access_Heap_Node >
ArcHeap & ArcHeap< GT, Distance, Access_Heap_Node >::operator= ( ArcHeap< GT, Distance, Access_Heap_Node > &&  other)
inlinenoexcept

Move assignment transfers ownership of heap nodes and the distance, after emptying this heap as empty() does.

Definition at line 91 of file archeap.H.

References ArcHeap< GT, Distance, Access_Heap_Node >::access_node, ArcHeap< GT, Distance, Access_Heap_Node >::empty(), and Aleph::swap().

◆ operator=() [2/2]

template<class GT , class Distance , class Access_Heap_Node >
ArcHeap & ArcHeap< GT, Distance, Access_Heap_Node >::operator= ( const ArcHeap< GT, Distance, Access_Heap_Node > &  )
delete

◆ put_arc()

template<class GT , class Distance , class Access_Heap_Node >
void ArcHeap< GT, Distance, Access_Heap_Node >::put_arc ( typename GT::Arc *  arc,
typename GT::Node *  tgt 
)
inline

Insert or update an arc associated with a target node, keeping the smallest-distance arc per node in the heap.

If the distance throws, the heap is as it was, and tgt has in it the arc that it had, or none.

Definition at line 131 of file archeap.H.

References ArcHeap< GT, Distance, Access_Heap_Node >::access_node, Aleph::GenBinHeap< NodeType, Key, Compare >::get_compare(), Aleph::BinHeapNode< Key >::get_key(), Aleph::GenBinHeap< NodeType, Key, Compare >::insert(), and Aleph::GenBinHeap< NodeType, Key, Compare >::update().

Referenced by Aleph::Prim_Min_Spanning_Tree< GT, Distance, SA >::min_spanning_tree(), TEST(), TEST(), and TEST().

Member Data Documentation

◆ access_node

template<class GT , class Distance , class Access_Heap_Node >
Access_Heap_Node ArcHeap< GT, Distance, Access_Heap_Node >::access_node
private

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