|
ADS
Algorithms and Data Structures
|
a priority queue on a list, sorted by priority if Sorted, unsorted otherwise More...
#include <ADS/priority/ListPriorityQueue.h>
Public types | |
| using | Item = T |
| the type of the items | |
| using | Priority = P |
| the type of priorities | |
| using | Handle = typename List< Pair >::Pos |
| the cell of an item | |
| using | value_type = Pair |
| the type of the items of the view | |
| using | size_type = std::size_t |
| the type of the sizes | |
| using | difference_type = std::ptrdiff_t |
| the type of the distances between iterators | |
| using | reference = const Pair & |
| the type of a reference to an item of the view | |
| using | const_reference = const Pair & |
| the type of a constant reference to an item | |
| using | iterator = typename List< Pair >::const_iterator |
| the same as const_iterator | |
| using | const_iterator = typename List< Pair >::const_iterator |
| the iterator of the view, constant | |
Public member functions | |
| bool | empty (void) const |
| whether the queue has no item | |
| int | size (void) const |
| the number of items, \( n \) | |
| const T & | min (void) const |
| the item of smallest priority, in \( O( 1 ) \) time if sorted and \( O( n ) \) otherwise | |
| T | deleteMin (void) |
| removes the item of smallest priority and returns it, in \( O( 1 ) \) time if sorted and \( O( n ) \) otherwise | |
| Handle | insert (const T &x, const P &p) |
| inserts \( x \) with the priority \( p \) and gives its handle, in \( O( n ) \) time if sorted and \( O( 1 ) \) otherwise | |
| void | decrease (Handle &y, const P &p) |
| lowers to \( p \) the priority of the item of the handle \( y \), which stays valid, in \( O( n ) \) time if sorted and \( O( 1 ) \) otherwise | |
| const_iterator | begin (void) const |
| the first item of the view | |
| const_iterator | end (void) const |
| the end of the view | |
| const_iterator | cbegin (void) const |
| the same as begin() | |
| const_iterator | cend (void) const |
| the same as end() | |
a priority queue on a list, sorted by priority if Sorted, unsorted otherwise
| using ADS::ListPriorityQueue< T, P, Sorted >::const_iterator = typename List< Pair >::const_iterator |
the iterator of the view, constant
| using ADS::ListPriorityQueue< T, P, Sorted >::const_reference = const Pair & |
the type of a constant reference to an item
| using ADS::ListPriorityQueue< T, P, Sorted >::difference_type = std::ptrdiff_t |
the type of the distances between iterators
| using ADS::ListPriorityQueue< T, P, Sorted >::Handle = typename List< Pair >::Pos |
the cell of an item
| using ADS::ListPriorityQueue< T, P, Sorted >::Item = T |
the type of the items
| using ADS::ListPriorityQueue< T, P, Sorted >::iterator = typename List< Pair >::const_iterator |
the same as const_iterator
| using ADS::ListPriorityQueue< T, P, Sorted >::Priority = P |
the type of priorities
| using ADS::ListPriorityQueue< T, P, Sorted >::reference = const Pair & |
the type of a reference to an item of the view
| using ADS::ListPriorityQueue< T, P, Sorted >::size_type = std::size_t |
the type of the sizes
| using ADS::ListPriorityQueue< T, P, Sorted >::value_type = Pair |
the type of the items of the view
|
inlinenodiscard |
the first item of the view
|
inlinenodiscard |
the same as begin()
|
inlinenodiscard |
the same as end()
| void ADS::ListPriorityQueue< T, P, Sorted >::decrease | ( | Handle & | y, |
| const P & | p ) |
lowers to \( p \) the priority of the item of the handle \( y \), which stays valid, in \( O( n ) \) time if sorted and \( O( 1 ) \) otherwise
In pseudocode (section 10.1.1):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{decrease}( y , p ) \cr 2 & \quad \textbf{if}\ \textbf{not}\ \mathit{Sorted}\ \textbf{then} \ \text{set the priority of } y \text{ to } p;\ \textbf{return} \cr 3 & \quad x \gets \text{the item of } y;\ \text{remove } y \text{ from } L \cr 4 & \quad y \gets \mathrm{insert}( x , p )\quad \triangleright \ \text{in its new place, } n \text{ unchanged} \end{array}} \]
| T ADS::ListPriorityQueue< T, P, Sorted >::deleteMin | ( | void | ) |
removes the item of smallest priority and returns it, in \( O( 1 ) \) time if sorted and \( O( n ) \) otherwise
In pseudocode (section 10.1.1):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{deleteMin}() \cr 2 & \quad q \gets \text{the cell that } \mathrm{min}() \text{ reads};\ x \gets \text{the item of } q \cr 3 & \quad \text{remove } q \text{ from } L;\ n \gets n - 1; \ \textbf{return}\ x \end{array}} \]
|
nodiscard |
whether the queue has no item
|
inlinenodiscard |
the end of the view
| Handle ADS::ListPriorityQueue< T, P, Sorted >::insert | ( | const T & | x, |
| const P & | p ) |
inserts \( x \) with the priority \( p \) and gives its handle, in \( O( n ) \) time if sorted and \( O( 1 ) \) otherwise
In pseudocode (section 10.1.1), an item after those of equal priority:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( x , p ) \cr 2 & \quad q \gets \text{the head of } L \cr 3 & \quad \textbf{if}\ \mathit{Sorted}\ \textbf{then}\ q \gets \text{the first cell of priority above } p \text{, or the end of } L\quad \triangleright\ \text{stable} \cr 4 & \quad n \gets n + 1;\ \textbf{return}\ \text{the cell of } ( p , x ) \text{ inserted before } q \end{array}} \]
|
nodiscard |
the item of smallest priority, in \( O( 1 ) \) time if sorted and \( O( n ) \) otherwise
In pseudocode (section 10.1.1), \( L \) the list of the pairs \( ( p , x ) \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{min}() \cr 2 & \quad q \gets \text{the head of } L \text{ if } \mathit{Sorted} \text{, else the first cell of least priority, by a scan} \cr 3 & \quad \textbf{return}\ \text{the item of } q \end{array}} \]
|
nodiscard |
the number of items, \( n \)