jakeryan
asked on
collections.Queue with a definite capacity where old objects expire
Hello,
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):
(Empty)
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:
0) A
1) B
2) C
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:
Queue:
0) B
1) C
2) D
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:
0) D
Thanks in advance!
Jake
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
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):
(Empty)
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:
0) A
1) B
2) C
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:
Queue:
0) B
1) C
2) D
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:
0) D
Thanks in advance!
Jake
It would be easy enough to wrap an ArrayList in a Class to give you this functionality...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
FernandoSoto,
Based on the example you've given, that looks like it would do exactly what I need! Unfortunately, due to a more pressing bug I've had to roll back my project to a few weeks ago. I can't wait to try it out though. I just wanted to give you a heads up I didn't abandon this.
Jake
Based on the example you've given, that looks like it would do exactly what I need! Unfortunately, due to a more pressing bug I've had to roll back my project to a few weeks ago. I can't wait to try it out though. I just wanted to give you a heads up I didn't abandon this.
Jake
No problem. Let me know if you need any other help with this.
Fernando
Fernando
Hi Bob;
I would like to see a resolution to the problem seeming I gave jakeryan a solution that works and his statement was, "Based on the example you've given, that looks like it would do exactly what I need!"."
Yhanks;
Fernando
I would like to see a resolution to the problem seeming I gave jakeryan a solution that works and his statement was, "Based on the example you've given, that looks like it would do exactly what I need!"."
Yhanks;
Fernando
ASKER
Not abandoned, I needed more time. Thank you FernandoSoto! I'm sorry I couldn't test this earlier, but due to a very nasty bug in my program popping up, I had to resort to an older version and work my way back up to present. Your queue class worked for me!
No problem. Glad I was able to help. ;=)
Maybe you'd be better of with a simple array.