52#ifndef __ADS_HeapPriorityQueue
53 #define __ADS_HeapPriorityQueue
84template<
class T , std::totally_ordered P =
int ,
int D = 2 >
125 [[nodiscard]]
bool empty(
void )
const;
128 [[nodiscard]]
int size(
void )
const;
135 [[nodiscard]]
const T &
min(
void )
const;
217 static int parent(
int i ) {
return( ( i - 1 ) / D ); }
221 static int child(
int i ,
int j ) {
return( D * i + j + 1 ); }
261 void swap(
int i ,
int j );
267 void minHeapRestore(
int i ,
int dim );
270 [[nodiscard]]
bool owns( Handle y )
const;
274 [[nodiscard]]
bool isHeap(
void )
const;
277 std::vector< PriorityItem * > f_H;
290#include "ADS/priority/impl/HeapPriorityQueue.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The iterators that the containers of the library have in common, beyond the book: they give a contain...
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.
static int parent(int i)
the parent of the place
Definition HeapPriorityQueue.h:217
HeapPriorityQueue(const HeapPriorityQueue &)=delete
no copy: the handles point into the queue
HeapPriorityQueue & operator=(HeapPriorityQueue &&other) noexcept
the items of other, which is left empty, in place of these; its handles stay valid here
const_iterator cend(void) const
the same as end()
Definition HeapPriorityQueue.h:256
std::size_t size_type
the type of the sizes
Definition HeapPriorityQueue.h:232
IndirectIterator< typename std::vector< PriorityItem * >::const_iterator > const_iterator
the iterator of the view, constant
Definition HeapPriorityQueue.h:240
int size(void) const
the number of items,
HeapPriorityQueue(int n)
the empty queue of capacity (the PriorityQueue( n ) of the book)
std::ptrdiff_t difference_type
the type of the distances between iterators
Definition HeapPriorityQueue.h:234
std::vector< P > priorities(void) const
the heap: the priorities, by their place
const PriorityItem & const_reference
the type of a constant reference to an item
Definition HeapPriorityQueue.h:238
const_iterator begin(void) const
the first item of the view
Definition HeapPriorityQueue.h:246
bool empty(void) const
whether the queue has no item
int capacity(void) const
the largest number of items,
~HeapPriorityQueue()
the queue and its items destroyed
static int child(int i, int j)
the child of the place ,
Definition HeapPriorityQueue.h:221
void decrease(Handle y, const P &p)
lowers to the priority of the item of the handle , which moves up, in time
PriorityItem value_type
the type of the items of the view
Definition HeapPriorityQueue.h:230
T Item
the type of the items
Definition HeapPriorityQueue.h:99
Handle insert(const T &x, const P &p)
inserts with the priority and gives its handle, a new leaf moved up, in time
const_iterator end(void) const
the end of the view
Definition HeapPriorityQueue.h:250
const PriorityItem & reference
the type of a reference to an item of the view
Definition HeapPriorityQueue.h:236
P Priority
the type of the priorities
Definition HeapPriorityQueue.h:100
PriorityItem * Handle
what insert() gives
Definition HeapPriorityQueue.h:101
T deleteMin(void)
removes the item of smallest priority and returns it, the last leaf moved to the root and down,...
const P & minPriority(void) const
the smallest priority
const_iterator cbegin(void) const
the same as begin()
Definition HeapPriorityQueue.h:254
const T & min(void) const
the item of smallest priority, the root
const_iterator iterator
the same as const_iterator
Definition HeapPriorityQueue.h:243
HeapPriorityQueue(HeapPriorityQueue &&other) noexcept
the items of other, which is left empty; its handles stay valid here
HeapPriorityQueue & operator=(const HeapPriorityQueue &)=delete
no copy: the handles point into the queue
the random-access iterator I on pointers read through them, *it being **base; the items are constant
Definition Iterators.h:507
a pool of objects of type T in blocks of at most slots
Definition ObjectPool.h:108
the PRIORITYITEM of the book: priority, item, place in the vector
Definition HeapPriorityQueue.h:93
P priority
the priority
Definition HeapPriorityQueue.h:94
T value
the item
Definition HeapPriorityQueue.h:95
int pos
the place in the vector of the heap
Definition HeapPriorityQueue.h:96