[erlang-questions] Priority queue

Yerl <>
Wed Jun 27 23:02:37 CEST 2007


Thanks Ulf.

How I forgot this.

cheers
Y.

Ulf Wiger (TN/EAB) a écrit :
> 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:  
>> [mailto:] On Behalf Of Yerl
>> Sent: den 27 juni 2007 20:56
>> To: 
>> 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
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>>     
>  
>
>   




More information about the erlang-questions mailing list