Accessing items by index using ElementAt is obviously not a reasonable choice, as per .NET queue ElementAt performance.
Is there an alternative generic data structure that would be appropriate for this requirement?
My queue has a fixed capacity.
As per MSDN entry on the Queue class, “This class implements a queue as a circular array“, yet it doesn’t seem to expose any kind of indexing property.
Update: I have found C5’s implementation of a CircularQueue. It seems to fit the bill, but I would prefer not to have to import another external library if possible.
You can use a cyclic array. I.e. implement queue in array.
The implementation is pretty trivial, you don’t need to use external library, just implement it yourself. A hint: it’s easier to use
m_beginIndex, m_nElementsmembers thanm_beginIndex, m_endIndex.