joaoportela / CircularBuffer-CSharp

A simple, single file, implementation of a circular buffer in C#.
The Unlicense
228 stars 45 forks source link

Enumerating the circular buffer does not produce anything #31

Closed asm2025 closed 3 years ago

asm2025 commented 3 years ago

This code does not produce output from the circular buffer It only prints the content of the array. ` int[] values = new int[20]; Random rnd = new Random();

for (int i = 0; i < values.Length; i++) values[i] = rnd.Next(1, 99);

CircularBuffer buffer = new CircularBuffer(values.Length / 2);

Console.WriteLine(string.Join(", ", values));

foreach (int value in values) buffer.Add(value);

Console.WriteLine(string.Join(", ", buffer));

Console.ReadKey(); `

I think there might be an issue with this method

`private void innerInsert(T value) { _circularBuffer[_tail] = value; _tail = (_tail + 1) % _circularBuffer.Length; if (_tail == _head) // <- here { _head = (_head + 1) % _circularBuffer.Length; }

        // Count should not be greater than the length of the buffer when overriding 
        _count = _count < Length ? ++_count : _count;
    }`
asm2025 commented 3 years ago

Sorry, my mistake