add method

  1. @override
void add(
  1. T element
)
override

Adds an element to the buffer. Overwrites the oldest element if full.

Implementation

@override
void add(T element) {
  _buffer[_tail] = element;
  _tail = (_tail + 1) % _capacity;
  if (_isFull) {
    _head = (_head + 1) % _capacity;
  } else if (_tail == _head) {
    _isFull = true;
  }
}