1 #ifndef __OV_PRIORITY_QUEUE__
2 #define __OV_PRIORITY_QUEUE__
22 { listIter = it.listIter; }
25 { listIter++;
return *
this; }
37 {
return listIter == i.listIter; }
40 {
return listIter != i.listIter; }
43 typename list<T>::iterator listIter;
61 { listIter = it.listIter; }
64 { listIter++;
return *
this; }
73 {
return listIter == i.listIter; }
76 {
return listIter != i.listIter; }
79 typename list<T>::const_iterator listIter;
94 { theQueue.erase(i.listIter); }
117 { theQueue.clear(); }
120 {
return theQueue.empty() ; }
123 {
return theQueue.size(); }
159 { refQueue = it_.refQueue; batch=it_.batch; it = it_.it; }
163 if ( refQueue==
NULL )
throw "cannot increment uninitialized iterator";
164 if ( batch!=refQueue->end() )
166 if ( it != (*batch).queue.end() )
171 if ( batch!=refQueue->end() ) it = (*batch).queue.begin();
173 if ( batch!=refQueue->end() )
174 if ( it == (*batch).queue.end() ) ++(*
this);
181 { refQueue = it_.refQueue; batch=it_.batch; it = it_.it;
return *
this;}
183 { refQueue = it_.refQueue; batch=it_.batch; it = it_.it;
return *
this;}
191 if ( refQueue==
NULL )
throw "cannot increment uninitialized iterator";
192 if ( batch!=refQueue->end() )
193 if ( it != (*batch).queue.end() )
198 if ( batch!=refQueue->end() ) it = (*batch).queue.begin();
212 bool areEqual =
true;
213 areEqual = (refQueue == i.refQueue);
214 if ( areEqual && refQueue!=
NULL )
216 if ( (areEqual = (batch == i.batch)) )
217 if ( areEqual && batch!=refQueue->end() ) areEqual = (it==i.it);
225 return ! ( (*this)==i );
231 list< __ov_batchQueue_struct<T> > *refQueue;
232 typename list< __ov_batchQueue_struct<T> >
::iterator batch;
250 { refQueue = it_.refQueue; batch=it_.batch; it = it_.it; }
253 { refQueue = it_.refQueue; batch=it_.batch; it = it_.it;
return *
this; }
258 if ( refQueue==
NULL )
throw "cannot increment uninitialized iterator";
259 if ( batch!=refQueue->end() )
261 if ( it != (*batch).queue.end() )
266 if ( batch!=refQueue->end() ) it = (*batch).queue.begin();
268 if ( batch!=refQueue->end() )
269 if ( it==(*batch).queue.end() ) ++(*
this);
280 if ( refQueue==
NULL )
throw "cannot increment uninitialized iterator";
281 if ( batch!=refQueue->end() )
282 if ( it != (*batch).queue.end() )
287 if ( batch!=refQueue->end() ) it = (*batch).queue.begin();
295 {
return (T&)(*it); }
302 bool areEqual =
true;
303 areEqual = (refQueue == i.refQueue);
304 if ( areEqual && refQueue!=
NULL )
306 if ( (areEqual = (batch == i.batch)) )
307 if ( areEqual && batch!=refQueue->end() ) areEqual = (it==i.it);
315 return ! ( (*this)==i );
319 list< __ov_batchQueue_struct<T> > *refQueue;
348 (*(i.batch)).queue.erase(i.it);
349 if ((*(i.batch)).queue.empty()) queues.erase(i.batch);
369 i =
insert(data, newPriority);
377 minP =
min((
double)minP,priority);
378 maxP =
max((
double)maxP,priority);
381 typename list< __ov_batchQueue_struct<T> >
::iterator insBatch=queues.begin();
385 if ( insBatch!=queues.end() )
387 while ( insBatch!=queues.end() )
389 if ( priority>(*insBatch).priorityBegin ||
390 ( priority<=(*insBatch).priorityBegin && priority>(*insBatch).priorityEnd ) )
397 real pa = (1.+ priorityBoundPercent)*priority;
398 real pb = (1.- priorityBoundPercent)*priority;
400 bool createNew = insBatch==queues.end() ?
true : ( priority>(*insBatch).priorityBegin ?
true : false );
408 newQStruct.
priorityEnd = (insBatch==queues.end()) ?
409 min(pa,pb) :
min(
min(pa,pb),(*insBatch).priorityBegin);
410 queues.insert( insBatch, newQStruct );
412 i = (*insBatch).queue.insert(data,priority);
416 i = (*insBatch).queue.insert(data,priority);
420 newIter.refQueue = (list< __ov_batchQueue_struct<T> > *) &queues;
421 newIter.batch = insBatch;
431 ib.batch = queues.begin();
432 ib.refQueue = &queues;
433 if (queues.begin()!=queues.end()) ib.it = (*(ib.batch)).queue.begin();
440 ie.batch = queues.end();
441 ie.refQueue = &queues;
454 ib.batch = queues.begin();
455 ib.refQueue = ( list< __ov_batchQueue_struct<T> > * )&queues;
456 if (queues.begin()!=queues.end()) ib.it = (*(ib.batch)).queue.begin();
463 ie.batch = queues.end();
464 ie.refQueue = ( list< __ov_batchQueue_struct<T> > * )&queues;
475 {
return queues.empty(); }
481 s+=(*i).queue.size();
486 {
return queues.size(); }
489 list< __ov_batchQueue_struct<T> > queues;
490 real priorityBoundPercent;