53 heap = std::make_unique<int[]>( maxsize );
54 p = std::make_unique<double[]>( maxsize );
55 pos = std::make_unique<int[]>( maxId + 1 );
59 for ( i = 0; i <= maxId; i++ )
84 const int return_value = heap[0];
105 return key <= maxId && pos[key] >= 0;
110 return key <= maxId ? pos[key] : -1;
115 if ( size == maxsize || key > maxId || key < 0 )
133 if ( key < 0 || key > maxId )
135 const int i = pos[key];
143 heap[i] = heap[size];
155 while ( size > pi ) pi *= 2;
159 for ( i = size - 1; i >= 0; i-- )
174 if ( key < 0 || key > maxId )
183 if ( greater( p[
PARENT( i )], p[i] ) )
216 if (
LEFT(
id ) < size )
218 if (
RIGHT(
id ) < size )
223 min_child =
LEFT(
id );
228 if ( greater( p[
id], p[min_child] ) )
230 pos[heap[id]] = min_child;
231 pos[heap[min_child]] = id;
236 heap[id] = heap[min_child];
237 p[id] = p[min_child];
239 heap[min_child] = tmpT;
252 if ( key < 0 || key > maxId )
255 const int i = pos[key];
273 if ( key < 0 || key > maxId )
276 const int i = pos[key];
292 fprintf( stderr,
"Size: %d\nMaxSize: %d\n", size, maxsize );
294 for ( i = 0; i < size; i++ )
297 fprintf( stderr,
"id: %7d -> key: %7d -> id: %7d p: %7f\n", i, heap[i], pos[heap[i]], p[i] );
299 fprintf( stderr,
"\n" );
308 for ( i = 0; i < maxsize; i++ )
Thrown when trying to access an empty data set.
Thrown when something is added in a Full set.
PriorityQueue(int n, int maxId, bool min)
Create a priority queue of max size n \param n max size of the queuet \param p external vector repres...
void decreaseKey(int key)
void setPriority(int key, double new_p)
void insert(int key, double p)
bool smaller(double l, double r)
bool bigger(double l, double r)