Re: C# Deque found on the web--thanks to The Game Programming Wiki



Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote:
ModelBuilder wrote:
I'm probably missing something that you are requiring, but it would seem that
System.Collections.Generic.Queue does most of what you are looking for in a
class.

And even uses the "proper" name for the data structure: "queue". :)

The one thing you can't do with a Queue<> is look at any element other
than the next one to be dequeued. You can peek at that element without
removing it, but you can't look at any other. The posted class offers
more inspection mechanisms than .NET's queue classes.

However, I'd argue that if you find yourself needing to look at an
element other than the first one, then your design isn't really using a
queue, and thus a queue data structure is the wrong one to use (use a
LinkedList<> instead, for example, which also allows easy removal from
front, removal from back, and inspection of all elements within).

So, yes...if one finds themselves needing a queue, I agree that the
Queue<> class, which already exists in .NET, is the correct one to use
(or if pre-.NET 2.0, the non-generic System.Collections.Queue class)

Let me give the example of my own use of RandomAccessQueue, which sort
of explains its purpose.

I have a thread-pool. You can add items to the work queue of a thread-
pool, and normally that work queue is viewed as a perfectly normal
queue. However, sometimes I also need to insert items into the queue,
if a priority is specified - items with a higher priority need to get
executed first.

I *could* have used LinkedList for this (except that I originally wrote
it before 2.0, of course) but it feels more like a "queue with
occasional random access" than a normal linked list. (Finding the right
point to insert a new item is also quicker this way than with a linked
list.)

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: [PATCH] CFQ:optimize the cfq_should_preempt()
    ... to preempt higher priority queue. ... Prior to this patch, if both queues were idle, the first if statement ... So, firstly, the queue of higher priority should preempt the one of lower priority, ...
    (Linux-Kernel)
  • Re: mldonkey & traffic shaping -> WWW still slow
    ... download-class queue fills up and drops packets. ... > students in the lab as well as the author of HTB. ... > higher priority queue lengths, else the higher priority traffic will ... I'm quite sure it would work with a prio qdisc. ...
    (comp.os.linux.networking)
  • Re: maximum number of window message queue
    ... a thread that would post message to the UI thread to update screen. ... Those are big numbers (compared to the old 16-bit limits):) ... queue. ...
    (microsoft.public.vc.language)
  • Re: Laugh or Cry: You Decide
    ... > sounding much like they were saying: ... >>> higher priority in the queue. ...
    (uk.rec.driving)
  • Re: Laugh or Cry: You Decide
    ... sounding much like they were saying: ... >> higher priority in the queue. ... > Well, it made _me_ laugh. ...
    (uk.rec.driving)

Loading