Class CircularBuffer<T>
- Namespace
- LiteEntitySystem.Collections
- Assembly
- LiteEntitySystem.dll
Circular buffer.
When writing to a full buffer: PushBack -> removes this[0] / Front() PushFront -> removes this[Size-1] / Back()
public class CircularBuffer<T>
Type Parameters
T
- Inheritance
-
objectCircularBuffer<T>
Constructors
CircularBuffer(int)
Initializes a new instance of the CircularBuffer<T> class.
public CircularBuffer(int capacity)
Parameters
capacity
intBuffer capacity. Must be positive.
CircularBuffer(int, T[])
Initializes a new instance of the CircularBuffer<T> class.
public CircularBuffer(int capacity, T[] items)
Parameters
capacity
intBuffer capacity. Must be positive.
items
T[]Items to fill buffer with. Items length must be less or equal than capacity.
Properties
Capacity
Maximum capacity of the buffer. Elements pushed into the buffer after maximum capacity is reached (IsFull = true), will remove an element.
public int Capacity { get; }
Property Value
Count
Current buffer size (the number of elements that the buffer has).
public int Count { get; }
Property Value
IsEmpty
True if has no elements.
public bool IsEmpty { get; }
Property Value
IsFull
Boolean indicating if Circular is at full capacity. Adding more elements when the buffer is full will cause elements to be removed from the other end of the buffer.
public bool IsFull { get; }
Property Value
this[int]
Index access to elements in buffer. Index does not loop around like when adding elements, valid interval is [0;Size]
public ref T this[int index] { get; }
Parameters
index
intIndex of element to access.
Property Value
- T
Exceptions
- IndexOutOfRangeException
Thrown when index is outside of [; Size[ interval.
Methods
Back()
Element at the back of the buffer - this[Size - 1].
public T Back()
Returns
- T
The value of the element of type T at the back of the buffer.
Clear()
Clears the contents of the array. Size = 0, Capacity is unchanged.
public void Clear()
Front()
Element at the front of the buffer - this[0].
public T Front()
Returns
- T
The value of the element of type T at the front of the buffer.
PopBack()
Removes the element at the back of the buffer. Decreasing the Buffer size by 1.
public void PopBack()
PopFront()
Removes the element at the front of the buffer. Decreasing the Buffer size by 1.
public void PopFront()
PushBack(T)
Pushes a new element to the back of the buffer. Back()/this[Size-1] will now return this element.
When the buffer is full, the element at Front()/this[0] will be popped to allow for this new element to fit.
public void PushBack(T item)
Parameters
item
TItem to push to the back of the buffer
PushFront(T)
Pushes a new element to the front of the buffer. Front()/this[0] will now return this element.
When the buffer is full, the element at Back()/this[Size-1] will be popped to allow for this new element to fit.
public void PushFront(T item)
Parameters
item
TItem to push to the front of the buffer