Class CircularBuffer<T>
Circular buffer.
When writing to a full buffer: PushBack -> removes this[0] / Front() PushFront -> removes this[Size-1] / Back()
Inheritance
Namespace: LiteEntitySystem.Collections
Assembly: LiteEntitySystem.dll
Syntax
public class CircularBuffer<T>
Type Parameters
Name | Description |
---|---|
T |
Constructors
CircularBuffer(int)
Initializes a new instance of the CircularBuffer<T> class.
Declaration
public CircularBuffer(int capacity)
Parameters
Type | Name | Description |
---|---|---|
int | capacity | Buffer capacity. Must be positive. |
CircularBuffer(int, T[])
Initializes a new instance of the CircularBuffer<T> class.
Declaration
public CircularBuffer(int capacity, T[] items)
Parameters
Type | Name | Description |
---|---|---|
int | capacity | Buffer capacity. Must be positive. |
T[] | items | 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.
Declaration
public int Capacity { get; }
Property Value
Type | Description |
---|---|
int |
Count
Current buffer size (the number of elements that the buffer has).
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
IsEmpty
True if has no elements.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool |
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.
Declaration
public bool IsFull { get; }
Property Value
Type | Description |
---|---|
bool |
this[int]
Index access to elements in buffer. Index does not loop around like when adding elements, valid interval is [0;Size]
Declaration
public ref T this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | Index of element to access. |
Property Value
Type | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | Thrown when index is outside of [; Size[ interval. |
Methods
Back()
Element at the back of the buffer - this[Size - 1].
Declaration
public T Back()
Returns
Type | Description |
---|---|
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.
Declaration
public void Clear()
Front()
Element at the front of the buffer - this[0].
Declaration
public T Front()
Returns
Type | Description |
---|---|
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.
Declaration
public void PopBack()
PopFront()
Removes the element at the front of the buffer. Decreasing the Buffer size by 1.
Declaration
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.
Declaration
public void PushBack(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item 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.
Declaration
public void PushFront(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to push to the front of the buffer |