collections.Queue with a definite capacity where old objects expire
Posted on 2006-06-22
This is in VB.Net although C# may be acceptable too if it can be translated.
I'd like to use something FIFO like System.Collections.Generic.Queue but I'd also like it to have a maximum capacity so that if there are too many items in the queue, the oldest items will fall out of the queue (or expire) as new items are added. I don't want this queue to grow indefinitely.
Is there any way to do this, or is there another object like Queue that has this functionality?
In case you're still confused, this is what I need..
Queue (with a maximum capacity of 3):
This Queue (though I'm not sure if it can be done) should have a maximum size of 3.
When I add in A,B,C, in that order, A will be in 0, B will be in 1, and C will be in 2, like this:
But if I add a fourth item D, A will expire, B will be in 0, C will be in 1, and D will be in 2, like this:
I also need to pull items off the stack in a FIFO manner (like Queue's .dequeue), like this (from the B,C,D queue):
Dequeue (pop B off the stack), Dequeue (pop C off the stack) then the stack will look like this:
Thanks in advance!