Question
I have a list of items I am adding to, however this special list will delete anything past a given capacity. Note the order is maintained.
For the life of me, I can't think of the name of such a construct.
Consider
data = new SpecialListType(3); // set capacity to 3
data.Add("A");
data.Add("B");
data.Add("C");
data.Add("D");
data.Dump(); // returns {"B", "C", "D"}
What is this? Some form of a Set
or Buffer
? And is there a framework implementation of this in Java and .NET?
Solution
It's a bounded queue (a first-in-first-out queue with a fixed capacity).
This particular queue always allows addition of elements and silently remove head element for newly added element (when full).
In Java there is the CircularFifoQueue
that works exactly that way (see also Size-limited queue that holds last N elements in Java).
For .NET you'd take a look at:
Licensed under: CC-BY-SA with attribution
Not affiliated with softwareengineering.stackexchange