ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
IndexedHeapPair.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------- File IndexedHeapPair.h -------------------------*/
3/*--------------------------------------------------------------------------*/
54/*--------------------------------------------------------------------------*/
55/*----------------------------- DEFINITIONS --------------------------------*/
56/*--------------------------------------------------------------------------*/
57
58#ifndef __ADS_IndexedHeapPair
59 #define __ADS_IndexedHeapPair
60/* self-identification: #endif constant */
61
62/*--------------------------------------------------------------------------*/
63/*------------------------------ INCLUDES ----------------------------------*/
64/*--------------------------------------------------------------------------*/
65
66#include "ADS/Contract.h"
68
69#include <cstddef>
70
71/*--------------------------------------------------------------------------*/
72/*--------------------------- NAMESPACE ------------------------------------*/
73/*--------------------------------------------------------------------------*/
74
75namespace ADS
76{
77
78/*--------------------------------------------------------------------------*/
79/*------------------------- CLASS IndexedHeapPair --------------------------*/
80/*--------------------------------------------------------------------------*/
81
84template< class K , class Bd = K , unsigned D = 4 >
86{
87
88/*--------------------------------------------------------------------------*/
89 public:
90 using Key = K;
91 using Bound = Bd;
92
95 explicit IndexedHeapPair( int n = 0 ) : f_key( n ) , f_bound( n ) { }
96
99 void reset( int n ) {
100 f_key.reset( n );
101 f_bound.reset( n );
102 }
103
105 [[nodiscard]] int ids( void ) const { return( f_key.ids() ); }
106
108 [[nodiscard]] bool empty( void ) const { return( f_key.empty() ); }
109
111 [[nodiscard]] std::size_t size( void ) const { return( f_key.size() ); }
112
115 [[nodiscard]] bool contains( int id ) const {
116 return( f_key.contains( id ) );
117 }
118
121 [[nodiscard]] const K & key( int id ) const { return( f_key.key( id ) ); }
122
125 [[nodiscard]] const Bd & bound( int id ) const {
126 return( f_bound.key( id ) );
127 }
128
142 void push( int id , const K & k , const Bd & b );
143
156 void update( int id , const K & k , const Bd & b );
157
169 void erase( int id );
170
173 [[nodiscard]] int top( void ) const { return( f_key.top().id ); }
174
177 [[nodiscard]] const K & topKey( void ) const { return( f_key.top().key ); }
178
181 [[nodiscard]] const Bd & minBound( void ) const {
182 return( f_bound.top().key );
183 }
184
187 [[nodiscard]] int minBoundId( void ) const { return( f_bound.top().id ); }
188
202 int pop( void );
203
217 int popMinBound( void );
218
220 void clear( void ) {
221 f_key.clear();
222 f_bound.clear();
223 }
224
225/*--------------------------------------------------------------------------*/
226 private:
229
230 }; // end( class IndexedHeapPair )
231
232/*--------------------------------------------------------------------------*/
233
234} // end( namespace ADS )
235
236/*--------------------------------------------------------------------------*/
237/*-------------------------- IMPLEMENTATION --------------------------------*/
238/*--------------------------------------------------------------------------*/
239
240#include "ADS/priority/impl/IndexedHeapPair.tpp"
241
242/*--------------------------------------------------------------------------*/
243
244#endif /* IndexedHeapPair.h included */
245
246/*--------------------------------------------------------------------------*/
247/*----------------------- End File IndexedHeapPair.h -----------------------*/
248/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
A -ary heap of the integers with keys and decrease-key, beyond the book: the heap of DaryHeap [see D...
a -ary heap of the ids by their keys, the least on top, with decrease-key, its changes told through ...
Definition IndexedDaryHeap.h:136
int pop(void)
removes the id of least key and returns it, in time
IndexedHeapPair(int n=0)
the empty queue of the ids
Definition IndexedHeapPair.h:95
int top(void) const
the id of least key
Definition IndexedHeapPair.h:173
K Key
the type of the keys of selection
Definition IndexedHeapPair.h:90
bool contains(int id) const
whether the id is in the queue
Definition IndexedHeapPair.h:115
const Bd & minBound(void) const
the least bound of the ids in the queue
Definition IndexedHeapPair.h:181
bool empty(void) const
whether the queue has no id
Definition IndexedHeapPair.h:108
void update(int id, const K &k, const Bd &b)
sets the key of the id to and its bound to , each heap moving the id up or down, in time
int ids(void) const
the number of ids,
Definition IndexedHeapPair.h:105
void reset(int n)
the empty queue of the ids , the room kept
Definition IndexedHeapPair.h:99
void erase(int id)
removes the id from the queue, in time
int popMinBound(void)
removes the id of least bound and returns it, as pop() by the other heap
void clear(void)
removes all the ids, in time
Definition IndexedHeapPair.h:220
Bd Bound
the type of the bounds
Definition IndexedHeapPair.h:91
void push(int id, const K &k, const Bd &b)
inserts the id with the key and the bound , in time
int minBoundId(void) const
an id of least bound
Definition IndexedHeapPair.h:187
const K & key(int id) const
the key of an id in the queue
Definition IndexedHeapPair.h:121
const Bd & bound(int id) const
the bound of an id in the queue
Definition IndexedHeapPair.h:125
const K & topKey(void) const
the least key, that of top()
Definition IndexedHeapPair.h:177
std::size_t size(void) const
the number of ids in the queue,
Definition IndexedHeapPair.h:111
Definition ADT.h:96