Re: Decent datastructure for queue operations
- From: Robert Strandh <strandh@xxxxxxxx>
- Date: 30 Jan 2006 20:59:18 +0100
"meng" <meng234@xxxxxxxxx> writes:
> Hi guys,
>
> I've been developing a tool which has to use lots of queues, well a
> FIFO data structure. So far, I used lists but they are obviously not
> efficient as enqueue operation can take linear time (this is because
> existing entries are not enqueued again, and we need to sort of search
> the queue). Binary search has come into mind, but vector is still not a
> good candidate due to difficulty of insertion. Binary search tree might
> be an option, so...
>
> - does anyone here have a better idea?
> - or if a binary search tree is really a great idea, are there built-in
> LISP functions for it?
I can't figure out whether you are talking about a simple queue or a
priority queue.
For a simple queue, you can use a list with a pointer to the last
element (with appropriate use of a sentinel to simplify programming).
If you don't want to use a CONS cell per element, you can use a
circular buffer implemented as a vector, which you would then have to
resize from time to time; or you can use the Flexichain library from
cl.net which already does that for you.
For a priority queue, you need a more sophisticated data structure,
and you cannot get linear (even amortized) complexity of the
operations (as far as I know). The standard implementation uses a
heap which is implemented as a resizable vector. You can also use
other binary trees such as AVL, 2-3, skiplists, etc, but that would
probably be more expensive both in terms of space and time.
--
Robert Strandh
.
- References:
- Decent datastructure for queue operations
- From: meng
- Decent datastructure for queue operations
- Prev by Date: Re: Interesting developments since "Beating the averages"?
- Next by Date: Re: Interesting developments since "Beating the averages"?
- Previous by thread: Re: Decent datastructure for queue operations
- Next by thread: Re: Decent datastructure for queue operations
- Index(es):
Relevant Pages
|
|