ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ListPriorityQueue.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------ File ListPriorityQueue.h ------------------------*/
3/*--------------------------------------------------------------------------*/
30/*--------------------------------------------------------------------------*/
31/*----------------------------- DEFINITIONS --------------------------------*/
32/*--------------------------------------------------------------------------*/
33
34#ifndef __ADS_ListPriorityQueue
35 #define __ADS_ListPriorityQueue
36/* self-identification: #endif constant */
37
38/*--------------------------------------------------------------------------*/
39/*------------------------------ INCLUDES ----------------------------------*/
40/*--------------------------------------------------------------------------*/
41
42#include "ADS/Contract.h"
44#include "ADS/sequence/List.h"
45
46#include <concepts>
47#include <cstddef>
48#include <utility>
49
50/*--------------------------------------------------------------------------*/
51/*--------------------------- NAMESPACE ------------------------------------*/
52/*--------------------------------------------------------------------------*/
53
54namespace ADS
55{
56
57/*--------------------------------------------------------------------------*/
58/*------------------------ CLASS ListPriorityQueue -------------------------*/
59/*--------------------------------------------------------------------------*/
60
63template< class T , std::totally_ordered P = int , bool Sorted = true >
65{
66
67 using Pair = std::pair< P , T >;
68
69/*--------------------------------------------------------------------------*/
70 public:
71 using Item = T;
72 using Priority = P;
73 using Handle = typename List< Pair >::Pos;
74
76 [[nodiscard]] bool empty( void ) const;
77
79 [[nodiscard]] int size( void ) const;
80
95 [[nodiscard]] const T & min( void ) const;
96
112 T deleteMin( void );
113
130 Handle insert( const T & x , const P & p );
131
151 void decrease( Handle & y , const P & p );
152
153/*------------------------- THE STANDARD INTERFACE -------------------------*/
154
155 // a constant view of the pairs ( priority , item ), by priority when the
156 // list is sorted, bidirectional; a change through it would break the order
157
159 using value_type = Pair;
161 using size_type = std::size_t;
163 using difference_type = std::ptrdiff_t;
165 using reference = const Pair &;
167 using const_reference = const Pair &;
172
174 [[nodiscard]] const_iterator begin( void ) const { return( f_L.begin() ); }
176 [[nodiscard]] const_iterator end( void ) const { return( f_L.end() ); }
178 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
180 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }
181
182/*--------------------------------------------------------------------------*/
183 private:
185 [[nodiscard]] Handle first( void ) const;
186
188 [[nodiscard]] Handle after( const P & p ) const;
189
191 [[nodiscard]] bool owns( Handle y ) const;
192
194 [[nodiscard]] bool consistent( void ) const;
195
196 List< Pair > f_L;
197 int f_size = 0;
198
199 }; // end( class ListPriorityQueue )
200
201/*--------------------------------------------------------------------------*/
202
203} // end( namespace ADS )
204
205/*--------------------------------------------------------------------------*/
206/*-------------------------- IMPLEMENTATION --------------------------------*/
207/*--------------------------------------------------------------------------*/
208
209#include "ADS/priority/impl/ListPriorityQueue.tpp"
210
211/*--------------------------------------------------------------------------*/
212
213#endif /* ListPriorityQueue.h included */
214
215/*--------------------------------------------------------------------------*/
216/*---------------------- End File ListPriorityQueue.h ----------------------*/
217/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The LIST of the book: a SEQUENCE [see ADT.h] realized as a bidirectional circular list of cells with ...
The PRIORITYQUEUE of section 10.1, with decreasing priority, in two concepts.
a priority queue on a list, sorted by priority if Sorted, unsorted otherwise
Definition ListPriorityQueue.h:65
const_iterator cend(void) const
the same as end()
Definition ListPriorityQueue.h:180
const Pair & const_reference
the type of a constant reference to an item
Definition ListPriorityQueue.h:167
void decrease(Handle &y, const P &p)
lowers to the priority of the item of the handle , which stays valid, in time if sorted and otherw...
std::ptrdiff_t difference_type
the type of the distances between iterators
Definition ListPriorityQueue.h:163
T deleteMin(void)
removes the item of smallest priority and returns it, in time if sorted and otherwise
Pair value_type
the type of the items of the view
Definition ListPriorityQueue.h:159
typename List< Pair >::const_iterator const_iterator
the iterator of the view, constant
Definition ListPriorityQueue.h:171
T Item
the type of the items
Definition ListPriorityQueue.h:71
typename List< Pair >::const_iterator iterator
the same as const_iterator
Definition ListPriorityQueue.h:169
const_iterator end(void) const
the end of the view
Definition ListPriorityQueue.h:176
const_iterator begin(void) const
the first item of the view
Definition ListPriorityQueue.h:174
const T & min(void) const
the item of smallest priority, in time if sorted and otherwise
P Priority
the type of priorities
Definition ListPriorityQueue.h:72
const_iterator cbegin(void) const
the same as begin()
Definition ListPriorityQueue.h:178
bool empty(void) const
whether the queue has no item
typename List< Pair >::Pos Handle
the cell of an item
Definition ListPriorityQueue.h:73
int size(void) const
the number of items,
Handle insert(const T &x, const P &p)
inserts with the priority and gives its handle, in time if sorted and otherwise
const Pair & reference
the type of a reference to an item of the view
Definition ListPriorityQueue.h:165
std::size_t size_type
the type of the sizes
Definition ListPriorityQueue.h:161
Iterator< true > const_iterator
the iterator on the constant items
Definition List.h:324
Cell * Pos
a position is the address of a cell
Definition List.h:132
Definition ADT.h:96