Class CircularBuffer<T>
Circular buffer.
When writing to a full buffer: PushBack -> removes this[0] / Front() PushFront -> removes this[Size-1] / Back()
this implementation is inspired by http://www.boost.org/doc/libs/1_53_0/libs/circular_buffer/doc/circular_buffer.html because I liked their interface.
Inheritance
Implements
Inherited Members
Namespace: HurricaneVR.Framework.Shared.Utilities
Assembly: HurricaneVR.Framework.dll
Syntax
public class CircularBuffer<T> : IEnumerable<T>, IEnumerable
Type Parameters
| Name | Description |
|---|---|
| T |
Constructors
| Improve this Doc View SourceCircularBuffer(Int32)
Declaration
public CircularBuffer(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | capacity |
CircularBuffer(Int32, T[])
Initializes a new instance of the CircularBuffer<T> class.
Declaration
public CircularBuffer(int capacity, T[] items)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | capacity | Buffer capacity. Must be positive. |
| T[] | items | Items to fill buffer with. Items length must be less than capacity. Suggestion: use Skip(x).Take(y).ToArray() to build this argument from any enumerable. |
Properties
| Improve this Doc View SourceCapacity
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 |
|---|---|
| System.Int32 |
IsEmpty
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsFull
Declaration
public bool IsFull { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Item[Int32]
Declaration
public T this[int index] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index |
Property Value
| Type | Description |
|---|---|
| T |
Size
Current buffer size (the number of elements that the buffer has).
Declaration
public int Size { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Methods
| Improve this Doc View SourceBack()
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. |
Dequeue(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 Dequeue(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | Item to push to the back of the buffer |
Enqueue(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 Enqueue(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | Item to push to the front of the buffer |
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. |
GetEnumerator()
Declaration
public IEnumerator<T> GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<T> |
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()
ToArray()
Copies the buffer contents to an array, according to the logical contents of the buffer (i.e. independent of the internal order/contents)
Declaration
public T[] ToArray()
Returns
| Type | Description |
|---|---|
| T[] | A new array with a copy of the buffer contents. |
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |