|
ADS
Algorithms and Data Structures
|
The PRIORITYQUEUE [see PriorityQueue.h] on a heap. More...
#include "ADS/Contract.h"#include "ADS/Iterators.h"#include "ADS/memory/ObjectPool.h"#include "ADS/priority/PriorityQueue.h"#include <concepts>#include <cstddef>#include <memory>#include <utility>#include <vector>#include "ADS/priority/impl/HeapPriorityQueue.tpp"Go to the source code of this file.
Classes | |
| class | ADS::HeapPriorityQueue< T, P, D > |
| a priority queue on a \( d \)-ary min-heap of bounded capacity, \( d \) the parameter D More... | |
| struct | ADS::HeapPriorityQueue< T, P, D >::PriorityItem |
| the PRIORITYITEM of the book: priority, item, place in the vector More... | |
Namespaces | |
| namespace | ADS |
The PRIORITYQUEUE [see PriorityQueue.h] on a heap.
HeapPriorityQueue is the heap of section 10.1.3, a vector \( H[ 0 .. n - 1 ] \) of capacity \( c \) holding a \( d \)-ary tree that is full but for the rightmost leaves of the last level, each node not smaller than its parent: the children of the place \( i \) are \( d i + 1 , \ldots , d i + d \) and its parent is \( \lfloor ( i - 1 ) / d \rfloor \) (with \( d = 2 \), \( l( i ) = 2 i + 1 \), \( r( i ) = 2 i + 2 \) and \( p( i ) = \lfloor ( i - 1 ) / 2 \rfloor \)). insert() and decrease() move the item up, deleteMin() moves the last leaf down from the root [see minHeapRestore()], in \( O( \log_d n ) \) and \( O( d \log_d n ) \) time, the tree having \( \lceil \log_d ( ( d - 1 ) n + 1 ) \rceil \) levels; each item knows its place, kept by swap(), and so the handle finds it (exercise 10.6 for \( d > 2 \)). Beyond the book, the items come from an ObjectPool [see ObjectPool.h] of the queue, which takes back the item of deleteMin() for the next insert(), so that an item costs no call to the allocator and the items in use stay close in memory.
The contracts [see Contract.h]: min(), minPriority() and deleteMin() need a queue that is not empty, insert() one that is not full, and decrease() a handle of an item of this queue and a priority not larger than its own; the invariant, checked at level 3 in \( O( n ) \) time, is the order of the heap together with the places that the items remember. On a heap of more than 1024 items only the root and the last item are checked, so that a long sequence of operations at the level 3 stays linear. The operations are defined in HeapPriorityQueue.tpp.