ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
TreePriorityQueue.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------ File TreePriorityQueue.h ------------------------*/
3/*--------------------------------------------------------------------------*/
30/*--------------------------------------------------------------------------*/
31/*----------------------------- DEFINITIONS --------------------------------*/
32/*--------------------------------------------------------------------------*/
33
34#ifndef __ADS_TreePriorityQueue
35 #define __ADS_TreePriorityQueue
36/* self-identification: #endif constant */
37
38/*--------------------------------------------------------------------------*/
39/*------------------------------ INCLUDES ----------------------------------*/
40/*--------------------------------------------------------------------------*/
41
42#include "ADS/Contract.h"
43#include "ADS/Iterators.h"
45#include "ADS/tree/SearchTree.h"
46
47#include <concepts>
48#include <cstddef>
49#include <utility>
50#include <vector>
51
52/*--------------------------------------------------------------------------*/
53/*--------------------------- NAMESPACE ------------------------------------*/
54/*--------------------------------------------------------------------------*/
55
56namespace ADS
57{
58
59/*--------------------------------------------------------------------------*/
60/*------------------------ CLASS TreePriorityQueue -------------------------*/
61/*--------------------------------------------------------------------------*/
62
65template< class T , std::totally_ordered P = int >
67{
68
69 using Key = std::pair< P , long >;
70
71/*--------------------------------------------------------------------------*/
72 public:
73 using Item = T;
74 using Priority = P;
75 using Handle = long;
76
78 [[nodiscard]] bool empty( void ) const;
79
81 [[nodiscard]] int size( void ) const;
82
86 [[nodiscard]] const T & min( void ) const;
87
104 T deleteMin( void );
105
121 Handle insert( const T & x , const P & p );
122
137 void decrease( Handle y , const P & p );
138
139/*------------------------- THE STANDARD INTERFACE -------------------------*/
140
141 // a constant view of the pairs ( ( priority , number of insertion ) ,
142 // item ) in increasing order of priority, bidirectional, those of the tree
143
147 using const_iterator = typename RedBlackTree< Key , T >::const_iterator;
150
152 [[nodiscard]] const_iterator begin( void ) const { return( f_t.begin() ); }
154 [[nodiscard]] const_iterator end( void ) const { return( f_t.end() ); }
156 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
158 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }
159
160/*--------------------------------------------------------------------------*/
161 private:
163 [[nodiscard]] bool consistent( void ) const;
164
166 std::vector< P > f_p;
167
168 }; // end( class TreePriorityQueue )
169
170/*--------------------------------------------------------------------------*/
171
172} // end( namespace ADS )
173
174/*--------------------------------------------------------------------------*/
175/*-------------------------- IMPLEMENTATION --------------------------------*/
176/*--------------------------------------------------------------------------*/
177
178#include "ADS/priority/impl/TreePriorityQueue.tpp"
179
180/*--------------------------------------------------------------------------*/
181
182#endif /* TreePriorityQueue.h included */
183
184/*--------------------------------------------------------------------------*/
185/*---------------------- End File TreePriorityQueue.h ----------------------*/
186/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The iterators that the containers of the library have in common, beyond the book: they give a contain...
The PRIORITYQUEUE of section 10.1, with decreasing priority, in two concepts.
The binary search tree (ABR) and the Red-Black tree of the book, as a DICTIONARY [see ADT....
std::pair< K, V > value_type
Definition SearchTree.h:521
a priority queue on a Red-Black tree of the pairs of a priority and of a number of insertion
Definition TreePriorityQueue.h:67
const_iterator cend(void) const
the same as end()
Definition TreePriorityQueue.h:158
const_iterator end(void) const
the end of the view
Definition TreePriorityQueue.h:154
long Handle
the number of insertion of an item
Definition TreePriorityQueue.h:75
P Priority
the type of the priorities
Definition TreePriorityQueue.h:74
T Item
the type of the items
Definition TreePriorityQueue.h:73
const T & min(void) const
the item of smallest priority, the leftmost node of the tree, in time
typename RedBlackTree< Key, T >::const_iterator const_iterator
the iterator of the view, constant
Definition TreePriorityQueue.h:147
Handle insert(const T &x, const P &p)
inserts with the priority and gives its handle, in time
typename RedBlackTree< Key, T >::value_type value_type
the type of the items of the view
Definition TreePriorityQueue.h:145
const_iterator begin(void) const
the first item of the view
Definition TreePriorityQueue.h:152
T deleteMin(void)
removes the item of smallest priority and returns it, in time
void decrease(Handle y, const P &p)
lowers to the priority of the item of the handle , in time
int size(void) const
the number of items,
bool empty(void) const
whether the queue has no item
const_iterator iterator
the same as const_iterator
Definition TreePriorityQueue.h:149
const_iterator cbegin(void) const
the same as begin()
Definition TreePriorityQueue.h:156
SearchTree< K, V, true > RedBlackTree
the Red-Black tree of section 6.2
Definition SearchTree.h:619
Definition ADT.h:96