Circular buffer.
More...
Inherits IEnumerable< T >.
|
| CircularBuffer (int capacity) |
| Initializes a new instance of the CircularBuffer<T> class. More...
|
|
| CircularBuffer (int capacity, T[] items) |
| Initializes a new instance of the CircularBuffer<T> class. More...
|
|
T | Front () |
| Element at the front of the buffer - this[0]. More...
|
|
T | Back () |
| Element at the back of the buffer - this[Size - 1]. More...
|
|
void | PushBack (T item) |
| Pushes a new element to the back of the buffer. Back()/this[Size-1] will now return this element. More...
|
|
void | PushFront (T item) |
| Pushes a new element to the front of the buffer. Front()/this[0] will now return this element. More...
|
|
void | PopBack () |
| Removes the element at the back of the buffer. Decreasing the Buffer size by 1. More...
|
|
void | PopFront () |
| Removes the element at the front of the buffer. Decreasing the Buffer size by 1. More...
|
|
void | Clear () |
| Clears the contents of the array. Size = 0, Capacity is unchanged. More...
|
|
T[] | ToArray () |
| Copies the buffer contents to an array, according to the logical contents of the buffer (i.e. independent of the internal order/contents) More...
|
|
IList< ArraySegment< T > > | ToArraySegments () |
| Get the contents of the buffer as 2 ArraySegments. Respects the logical contents of the buffer, where each segment and items in each segment are ordered according to insertion. More...
|
|
IEnumerator< T > | GetEnumerator () |
| Returns an enumerator that iterates through this buffer. More...
|
|
|
int | Capacity [get] |
| Maximum capacity of the buffer. Elements pushed into the buffer after maximum capacity is reached (IsFull = true), will remove an element. More...
|
|
bool | IsFull [get] |
| 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. More...
|
|
bool | IsEmpty [get] |
| True if has no elements. More...
|
|
int | Size [get] |
| Current buffer size (the number of elements that the buffer has). More...
|
|
T | this[int index] [get, set] |
| Index access to elements in buffer. Index does not loop around like when adding elements, valid interval is [0;Size[ More...
|
|
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.
◆ CircularBuffer() [1/2]
Initializes a new instance of the CircularBuffer<T> class.
- Parameters
-
capacity | Buffer capacity. Must be positive. |
◆ CircularBuffer() [2/2]
Initializes a new instance of the CircularBuffer<T> class.
- Parameters
-
capacity | Buffer capacity. Must be positive. |
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. |
◆ Back()
Element at the back of the buffer - this[Size - 1].
- Returns
- 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.
- Exceptions
-
◆ Front()
Element at the front of the buffer - this[0].
- Returns
- The value of the element of type T at the front of the buffer.
◆ GetEnumerator()
Returns an enumerator that iterates through this buffer.
- Returns
- An enumerator that can be used to iterate this collection.
◆ PopBack()
Removes the element at the back of the buffer. Decreasing the Buffer size by 1.
◆ PopFront()
Removes the element at the front of the buffer. Decreasing the Buffer size by 1.
◆ PushBack()
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.
- Parameters
-
item | Item to push to the back of the buffer |
◆ PushFront()
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.
- Parameters
-
item | Item to push to the front of the buffer |
◆ ToArray()
Copies the buffer contents to an array, according to the logical contents of the buffer (i.e. independent of the internal order/contents)
- Returns
- A new array with a copy of the buffer contents.
◆ ToArraySegments()
Get the contents of the buffer as 2 ArraySegments. Respects the logical contents of the buffer, where each segment and items in each segment are ordered according to insertion.
Fast: does not copy the array elements. Useful for methods like Send(IList<ArraySegment<Byte>>)
.
Segments may be empty.
- Returns
- An IList with 2 segments corresponding to the buffer content.
◆ Capacity
Maximum capacity of the buffer. Elements pushed into the buffer after maximum capacity is reached (IsFull = true), will remove an element.
◆ IsEmpty
◆ 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.
◆ Size
Current buffer size (the number of elements that the buffer has).
◆ this[int index]
Index access to elements in buffer. Index does not loop around like when adding elements, valid interval is [0;Size[
- Parameters
-
index | Index of element to access. |
- Exceptions
-
IndexOutOfRangeException | Thrown when index is outside of [; Size[ interval. |