[erlang-questions] How can I implement a priority queue with Erlang?

Jeffrey Chen bitcowboy@REDACTED
Fri Aug 31 06:46:47 CEST 2007


Thanks David. That're indeed a lot of traversals in the exchange
operate, and that's why I think it's inefficient. I'll try tree
structure later.

On 8/30/07, David Mercer <dmercer@REDACTED> wrote:
> On Thursday, August 30, 2007 at 07:34, Jeffrey Chen wrote:
> > I'm trying to implement a priority queue using heap struct. But I
> > can't do that efficient. Can anybody help me? I'll post my code below.
>
> I'm thinking heap structures are not going to be very efficient in Erlang.
> Not having looked at your code in particular, but if I recall correctly,
> heaps are efficient when you have random access into an array.  In Erlang,
> you'll be doing a lot of list traversals to get to the nth element, and to
> switch elements, etc.  It would be more efficient simply to do a single scan
> of the list and insert the element in the appropriate place.  Or use gb_tree
> (or some other tree structure) to help.  They are going to be more efficient
> than a linear list implementing a heap.
>
> Cheers,
>
> David
>
>
>


-- 
Victory won't come to me, unless I go to it.



More information about the erlang-questions mailing list