|
ADS
Algorithms and Data Structures
|
a priority queue on a Red-Black tree of the pairs of a priority and of a number of insertion More...
#include <ADS/priority/TreePriorityQueue.h>
Public types | |
| using | Item = T |
| the type of the items | |
| using | Priority = P |
| the type of the priorities | |
| using | Handle = long |
| the number of insertion of an item | |
| using | value_type = typename RedBlackTree< Key , T >::value_type |
| the type of the items of the view | |
| using | const_iterator = typename RedBlackTree< Key , T >::const_iterator |
| the iterator of the view, constant | |
| using | iterator = const_iterator |
| the same as const_iterator | |
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, the leftmost node of the tree, in \( O( \log n ) \) time | |
| T | deleteMin (void) |
| removes the item of smallest priority and returns it, in \( O( \log n ) \) time | |
| Handle | insert (const T &x, const P &p) |
| inserts \( x \) with the priority \( p \) and gives its handle, in \( O( \log n ) \) time | |
| void | decrease (Handle y, const P &p) |
| lowers to \( p \) the priority of the item of the handle \( y \), in \( O( \log n ) \) time | |
| 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 Red-Black tree of the pairs of a priority and of a number of insertion
| using ADS::TreePriorityQueue< T, P >::const_iterator = typename RedBlackTree< Key , T >::const_iterator |
the iterator of the view, constant
| using ADS::TreePriorityQueue< T, P >::Handle = long |
the number of insertion of an item
| using ADS::TreePriorityQueue< T, P >::Item = T |
the type of the items
| using ADS::TreePriorityQueue< T, P >::iterator = const_iterator |
the same as const_iterator
| using ADS::TreePriorityQueue< T, P >::Priority = P |
the type of the priorities
| using ADS::TreePriorityQueue< T, P >::value_type = typename RedBlackTree< Key , T >::value_type |
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::TreePriorityQueue< T, P >::decrease | ( | Handle | y, |
| const P & | p ) |
lowers to \( p \) the priority of the item of the handle \( y \), in \( O( \log n ) \) time
In pseudocode (section 10.1.2), the item moved to its new key:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{decrease}( y , p ) \cr 2 & \quad k \gets ( \mathit{pr}[ y ] , y );\ x \gets \mathrm{lookup}( T , k );\ \mathrm{remove}( T , k ) \cr 3 & \quad \mathit{pr}[ y ] \gets p;\ \mathrm{insert}( T , ( p , y ) , x ) \end{array}} \]
| T ADS::TreePriorityQueue< T, P >::deleteMin | ( | void | ) |
removes the item of smallest priority and returns it, in \( O( \log n ) \) time
In pseudocode (section 10.1.2), \( T \) the tree of the keys \( ( p , i ) \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{deleteMin}() \cr 2 & \quad ( k , x ) \gets \text{the key and the value of the leftmost node of } T\quad \triangleright\ \text{the least } ( p , i ) \cr 3 & \quad \mathrm{remove}( T , k );\ \textbf{return}\ x \end{array}} \]
|
nodiscard |
whether the queue has no item
|
inlinenodiscard |
the end of the view
| Handle ADS::TreePriorityQueue< T, P >::insert | ( | const T & | x, |
| const P & | p ) |
inserts \( x \) with the priority \( p \) and gives its handle, in \( O( \log n ) \) time
In pseudocode (section 10.1.2), \( \mathit{pr} \) the vector of the priorities by number of insertion:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( x , p ) \cr 2 & \quad i \gets |\mathit{pr}|\quad \triangleright \ \text{the handle, which breaks the ties} \cr 3 & \quad \mathrm{insert}( T , ( p , i ) , x );\ \text{append } p \text{ to } \mathit{pr};\ \textbf{return}\ i \end{array}} \]
|
nodiscard |
the item of smallest priority, the leftmost node of the tree, in \( O( \log n ) \) time
|
nodiscard |
the number of items, \( n \)