Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > efficient priority queue for a few descrete priority levels

Reply
Thread Tools

efficient priority queue for a few descrete priority levels

 
 
Marcel Müller
Guest
Posts: n/a
 
      04-26-2009
Hi,

I seek for a standard solution for a priority queue with the following
properties:

- a limited and small number of priorities
(constructor argument or template parameter)
- multiple writers
- multiple readers
- insert O(1)
- remove O(1)
- support for dedicated high priority readers that only handle requests
up to a certain priority level
- support for rollback (for readers only)

std:riority_queue has O(log n) and therefore does not fit.


Marcel
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      04-26-2009
Marcel Müller wrote:
> Hi,
>
> I seek for a standard solution for a priority queue with the following
> properties:
>
> - a limited and small number of priorities
> (constructor argument or template parameter)
> - multiple writers
> - multiple readers
> - insert O(1)
> - remove O(1)
> - support for dedicated high priority readers that only handle requests
> up to a certain priority level
> - support for rollback (for readers only)
>
> std:riority_queue has O(log n) and therefore does not fit.
>


comp.algorithms?
 
Reply With Quote
 
 
 
 
Marcel Müller
Guest
Posts: n/a
 
      04-27-2009
Hi,

Sam wrote:
> Given that your number of priorities is limited, all you need is a
> std::list for each individual priority.
>
> An object's priority selects its std::list. A push and a pop on a
> std::list is O(1).


oops, I think was too fixed on a single list with uncommitted items
still in the list and did not see the obvious solution.
All I have to do is to adjust the reader interface in the way, that it
starts looking at the highest priority, and the writer in a way that it
also signals readers with a lower priority limit. I think even a single
linked list should be fine, since push_back, pop_front and push_front
(for rollback) are O(1) for simple Head/Next/Tail lists too. And if I
join the lists the reader does no longer need to search all higher
priority lists each time. It only has to check for the individual tail
pointer corresponding to it's priority level.
Thanks for pushing me back to the right way.


Marcel
 
Reply With Quote
 
Marcel Müller
Guest
Posts: n/a
 
      04-27-2009
red floyd wrote:
> comp.algorithms?


You are right, I did not know of this group so far. However, Sam already
put me in the right direction this time.


Marcel
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Program blocked in Queue.Queue.get and Queue.Queue.put Kris Python 0 01-04-2012 03:46 PM
Is Queue.Queue.queue.clear() thread-safe? Russell Warren Python 4 06-27-2006 03:03 PM
Should I use shutter-priority or appurature-priority? ½ Confused Digital Photography 4 02-22-2006 09:48 AM
Question about Aperture priority and Shutter Priority John Edwards Digital Photography 8 01-05-2005 04:58 PM
Priority of different log4j.properties log levels ? Tobias Merler Java 0 10-07-2004 08:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57