93#ifndef __ADS_PairingHeap
94 #define __ADS_PairingHeap
109#include <type_traits>
126template<
class T , std::totally_ordered P = int ,
bool Aux = false ,
152 : f_pool( std::size_t( 1 ) << 24 ,
175 [[nodiscard]]
bool empty(
void )
const {
return( f_root ==
nullptr ); }
178 [[nodiscard]]
int size(
void )
const {
return( f_n ); }
182 [[nodiscard]]
const T &
min(
void )
const;
356 static Node * multiPass(
Node * x );
359 static void cut(
Node * x );
362 void unlinkMin(
void );
366 void detach(
Node * x );
369 void attach(
Node * x );
373 [[nodiscard]]
static bool tree(
const Node * x ,
int & n );
376 [[nodiscard]]
bool isHeap(
void )
const;
378 Node * f_root =
nullptr;
379 Node * f_min =
nullptr;
390template<
class T , std::totally_ordered P ,
bool Aux ,
class A >
403#include "ADS/priority/impl/PairingHeap.tpp"
The rules of the allocator-aware containers of the standard ([container.reqmts], [allocator....
The capabilities of the structures, beyond the book: what an algorithm may ask of its argument to cho...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
A pool of objects of one type, beyond the book: make() builds an object in a slot of the pool and fre...
The PRIORITYQUEUE of section 10.1, with decreasing priority, in two concepts.
an allocator of objects of type T, on huge pages for the large blocks
Definition HugePageAllocator.h:169
a pool of objects of type T in blocks of at most slots
Definition ObjectPool.h:108
a priority queue on a pairing heap, two-pass, or auxiliary two-pass if Aux
Definition PairingHeap.h:129
void decrease(Handle x, const P &p)
lowers to the priority of the node , cut with its subtree and linked with the root,...
allocator_type get_allocator(void) const
the allocator of the blocks of the nodes
Definition PairingHeap.h:158
~PairingHeap()
the heap and its nodes destroyed
PairingHeap & operator=(const PairingHeap &)=delete
no copy: the handles point into the heap
const P & minPriority(void) const
the smallest priority
PairingHeap(const PairingHeap &)=delete
no copy: the handles point into the heap
A allocator_type
the type of the allocator
Definition PairingHeap.h:156
T Item
the type of the items
Definition PairingHeap.h:143
P Priority
the type of the priorities
Definition PairingHeap.h:144
void update(Handle x, const P &p)
sets the priority of the node to , by decrease() or by increase()
PairingHeap(const A &alloc)
the empty heap, the blocks of its nodes from alloc
Definition PairingHeap.h:151
int size(void) const
the number of items,
Definition PairingHeap.h:178
PairingHeap(void)=default
the empty heap
bool empty(void) const
whether the heap has no item
Definition PairingHeap.h:175
Handle insert(const T &x, const P &p)
inserts with the priority and gives its handle, a tree of one node linked with the root,...
T erase(Handle x)
removes the item of the node , wherever it is, and returns it: the subtrees of its children joined by...
const T & min(void) const
the item of smallest priority
PairingHeap(PairingHeap &&other) noexcept
the items of other, which is left empty; its handles stay valid here
void increase(Handle x, const P &p)
raises to the priority of the node , which keeps its handle: the node leaves the heap as in erase() ...
Node * Handle
what insert() gives
Definition PairingHeap.h:145
T deleteMin(void)
removes the item of smallest priority and returns it, its children joined by two passes; the handle o...
constexpr bool enable_stable_references
whether the items of S keep their addresses while they are in it, so that a handle may be a pointer a...
Definition Capabilities.h:203
a node of the heap
Definition PairingHeap.h:135
Node * child
the leftmost child
Definition PairingHeap.h:138
T value
the item
Definition PairingHeap.h:137
Node * prev
the left sibling, or the parent
Definition PairingHeap.h:140
Node * next
the right sibling
Definition PairingHeap.h:139
P priority
the priority
Definition PairingHeap.h:136