View Single Post
Old Sep 4th, 2007, 4:11 PM   #1
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 329
Rep Power: 3 kruptof is on a distinguished road
Priority Queues Events

I have a priority queue which is filled with times (in seconds) which is associated with tasks. So far I queue the item, set a timer interval to the time of the item at the head of queue and when that time elapses I de-queue the item at the head of the queue and I set the timer interval to the next item in the at head of the queue, perform the task and then put the item back on the queue.

The problem with this is those tasks with long time intervals will never be performed because the ones with the shorter intervals keep popping up to the front of the queue.

The only solution that comes to mind, is when an item is de-queued, subtract the current item’s (the one that was just de-queued) time from all other items in the queue, this way seems rather long because you have to loop through all the items in every de-queue operation (which could occur frequently).

Are there any other simpler solutions.
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote