ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::ListPriorityQueue< T, P, Sorted > Class Template Reference

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()

Detailed description

template<class T, std::totally_ordered P = int, bool Sorted = true>
class ADS::ListPriorityQueue< T, P, Sorted >

a priority queue on a list, sorted by priority if Sorted, unsorted otherwise

Member typedef documentation

◆ const_iterator

template<class T, std::totally_ordered P = int, bool Sorted = true>
using ADS::ListPriorityQueue< T, P, Sorted >::const_iterator = typename List< Pair >::const_iterator

the iterator of the view, constant

◆ const_reference

template<class T, std::totally_ordered P = int, bool Sorted = true>
using ADS::ListPriorityQueue< T, P, Sorted >::const_reference = const Pair &

the type of a constant reference to an item

◆ difference_type

template<class T, std::totally_ordered P = int, bool Sorted = true>
using ADS::ListPriorityQueue< T, P, Sorted >::difference_type = std::ptrdiff_t

the type of the distances between iterators

◆ Handle

template<class T, std::totally_ordered P = int, bool Sorted = true>
using ADS::ListPriorityQueue< T, P, Sorted >::Handle = typename List< Pair >::Pos

the cell of an item

◆ Item

template<class T, std::totally_ordered P = int, bool Sorted = true>
using ADS::ListPriorityQueue< T, P, Sorted >::Item = T

the type of the items

◆ iterator

template<class T, std::totally_ordered P = int, bool Sorted = true>
using ADS::ListPriorityQueue< T, P, Sorted >::iterator = typename List< Pair >::const_iterator

the same as const_iterator

◆ Priority

template<class T, std::totally_ordered P = int, bool Sorted = true>
using ADS::ListPriorityQueue< T, P, Sorted >::Priority = P

the type of priorities

◆ reference

template<class T, std::totally_ordered P = int, bool Sorted = true>
using ADS::ListPriorityQueue< T, P, Sorted >::reference = const Pair &

the type of a reference to an item of the view

◆ size_type

template<class T, std::totally_ordered P = int, bool Sorted = true>
using ADS::ListPriorityQueue< T, P, Sorted >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class T, std::totally_ordered P = int, bool Sorted = true>
using ADS::ListPriorityQueue< T, P, Sorted >::value_type = Pair

the type of the items of the view

Member function documentation

◆ begin()

template<class T, std::totally_ordered P = int, bool Sorted = true>
const_iterator ADS::ListPriorityQueue< T, P, Sorted >::begin ( void ) const
inlinenodiscard

the first item of the view

◆ cbegin()

template<class T, std::totally_ordered P = int, bool Sorted = true>
const_iterator ADS::ListPriorityQueue< T, P, Sorted >::cbegin ( void ) const
inlinenodiscard

the same as begin()

◆ cend()

template<class T, std::totally_ordered P = int, bool Sorted = true>
const_iterator ADS::ListPriorityQueue< T, P, Sorted >::cend ( void ) const
inlinenodiscard

the same as end()

◆ decrease()

template<class T, std::totally_ordered P = int, bool Sorted = true>
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}} \]

Precondition
\( y \) is an item of this queue and \( p \) is not larger than its priority
Postcondition
\( y \) has the priority \( p \)

◆ deleteMin()

template<class T, std::totally_ordered P = int, bool Sorted = true>
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}} \]

Precondition
the queue is not empty
Postcondition
one item less, none of smaller priority than the one removed

◆ empty()

template<class T, std::totally_ordered P = int, bool Sorted = true>
bool ADS::ListPriorityQueue< T, P, Sorted >::empty ( void ) const
nodiscard

whether the queue has no item

◆ end()

template<class T, std::totally_ordered P = int, bool Sorted = true>
const_iterator ADS::ListPriorityQueue< T, P, Sorted >::end ( void ) const
inlinenodiscard

the end of the view

◆ insert()

template<class T, std::totally_ordered P = int, bool Sorted = true>
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}} \]

Postcondition
one item more

◆ min()

template<class T, std::totally_ordered P = int, bool Sorted = true>
const T & ADS::ListPriorityQueue< T, P, Sorted >::min ( void ) const
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}} \]

Precondition
the queue is not empty

◆ size()

template<class T, std::totally_ordered P = int, bool Sorted = true>
int ADS::ListPriorityQueue< T, P, Sorted >::size ( void ) const
nodiscard

the number of items, \( n \)


The documentation for this class was generated from the following file: