[erlang-questions] : : queues (previously: documentation of data structures)

Anders Ramsell anders@REDACTED
Mon Dec 17 15:59:04 CET 2007


Raimo Niskanen wrote:
 > If speed is not important at all you can of course do
 > Q1 = queue:from_list([X || X <- queue:to_list(Q0), X =/= Y]
 > and such.

To my defence I only said that it didn't matter it couldn't be
O(1). A reasonably efficient function is always nice. :-)


 > Proposed new API (along the lines of Anders Ramsell's suggestion:
 >
 > Introduce the notion of a first .. last order in the queue.
 > Elements normally enters the first end and exits the last end.

Well, it does look a lot better than what we have today, but it
seems "backwards". I do think you enter a queue at the end.
Actually the only operations on a "queue" I tend to use is
(avoiding API names altogether) these:

- create a queue
- add element to queue (which is then last in queue)
- remove first element from queue for processing (waited the longest)
- remove element from queue (no longer relevant)

The purpose being handling resources in the order they arrive
with the extra constraint that some resources "go away" before
it's their turn.

That said, I'm sure the other operations also could be very useful
in certain circumstances. And even though I beleive that what you
call "delete(Item, Q1) -> Q2" is what I called 'drop' (and I'd
still like that one added very much) I don't think the queue
module should house a wide variety of "list like" funtions.

/Anders Ramsell



More information about the erlang-questions mailing list