[erlang-questions] Priority queue

David Mercer dmercer@REDACTED
Fri Jul 6 15:39:18 CEST 2007


What was wrong with Mr. Wiger's solution?  I thought his was quite good (and
I filed it away in my brain for future use).

David

-----Original Message-----
From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Eranga Udesh
Sent: Friday, July 06, 2007 07:13
To: 'Ulf Wiger (TN/EAB)'; 'Yerl'; erlang-questions@REDACTED
Subject: Re: [erlang-questions] Priority queue

How to handle Priority Queues between processes, while keeping efficient
message retrieval?

BRgds,
- Eranga


-----Original Message-----
From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Ulf Wiger (TN/EAB)
Sent: Thursday, June 28, 2007 2:17 AM
To: Yerl; erlang-questions@REDACTED
Subject: Re: [erlang-questions] Priority queue


You can use a gb_trees structure:

in(Item, Prio, Q) ->
   gb_trees:insert({Prio,now()}, Item, Q).

out(Q) ->
   gb_trees:take_smallest(Q).

peek(Q) ->
   gb_trees:smallest(Q).

The order will be FIFO. If you want LIFO, you 
could negate the Prio value and take_largest
instead.

BR,
Ulf W

> -----Original Message-----
> From: erlang-questions-bounces@REDACTED 
> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of Yerl
> Sent: den 27 juni 2007 20:56
> To: erlang-questions@REDACTED
> Subject: [erlang-questions] Priority queue
> 
> Hi Folks!
> 
> I'm looking for a robust implementation of "Priority queue"
> (http://en.wikipedia.org/wiki/Priority_queue) in Erlang.
> 
> Any pointer?
> 
> cheers
> Y.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://www.erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list