1
Vote

Overflow is not updating the head index

description

Buffer Get should always return the elements from oldest to newest. This does not happen

I did a test that shows the presence of the bug.
{
    var buffer = new CircularBuffer<byte>(5, true);
    buffer.Put(1);
    buffer.Put(2);
    buffer.Put(3);
    buffer.Put(4);
    buffer.Put(5);
    buffer.Put(6);

    // this would be the correct result.
    CollectionAssert.AreEqual(new byte[] { 2, 3, 4, 5, 6 }, buffer.Get(5));
    // but it's currently returning: 6, 2, 3, 4, 5
}
This happens because when the buffer overflows you need to update the head.

comments