54 heap = std::make_unique<int[]>( maxsize );
55 p = std::make_unique<double[]>( maxsize );
56 pos = std::make_unique<int[]>( maxId + 1 );
60 for ( i = 0; i <= maxId; i++ )
85 const int return_value = heap[0];
106 return key <= maxId && pos[key] >= 0;
111 return key <= maxId ? pos[key] : -1;
116 if ( size == maxsize || key > maxId || key < 0 )
134 if ( key < 0 || key > maxId )
136 const int i = pos[key];
144 heap[i] = heap[size];
156 while ( size > pi ) pi *= 2;
160 for ( i = size - 1; i >= 0; i-- )
175 if ( key < 0 || key > maxId )
184 if ( greater( p[
PARENT( i )], p[i] ) )
217 if (
LEFT(
id ) < size )
219 if (
RIGHT(
id ) < size )
224 min_child =
LEFT(
id );
229 if ( greater( p[
id], p[min_child] ) )
231 pos[heap[id]] = min_child;
232 pos[heap[min_child]] = id;
237 heap[id] = heap[min_child];
238 p[id] = p[min_child];
240 heap[min_child] = tmpT;
253 if ( key < 0 || key > maxId )
256 const int i = pos[key];
274 if ( key < 0 || key > maxId )
277 const int i = pos[key];
293 fprintf( stderr,
"Size: %d\nMaxSize: %d\n", size, maxsize );
295 for ( i = 0; i < size; i++ )
298 fprintf( stderr,
"id: %7d -> key: %7d -> id: %7d p: %7f\n", i, heap[i], pos[heap[i]], p[i] );
300 fprintf( stderr,
"\n" );
309 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)