Battle Talent  V11
Public Member Functions | Properties | List of all members
CrossLink.CircularBuffer< T > Class Template Reference

Circular buffer. More...

Inherits IEnumerable< T >.

Public Member Functions

 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...
 
Front ()
 Element at the front of the buffer - this[0]. More...
 
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...
 

Properties

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...
 
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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CircularBuffer() [1/2]

CrossLink.CircularBuffer< T >.CircularBuffer ( int  capacity)

Initializes a new instance of the CircularBuffer<T> class.

Parameters
capacityBuffer capacity. Must be positive.

◆ CircularBuffer() [2/2]

CrossLink.CircularBuffer< T >.CircularBuffer ( int  capacity,
T[]  items 
)

Initializes a new instance of the CircularBuffer<T> class.

Parameters
capacityBuffer capacity. Must be positive.
itemsItems 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.

Member Function Documentation

◆ Back()

T CrossLink.CircularBuffer< T >.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()

void CrossLink.CircularBuffer< T >.Clear ( )

Clears the contents of the array. Size = 0, Capacity is unchanged.

Exceptions
NotImplementedException

◆ Front()

T CrossLink.CircularBuffer< T >.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()

IEnumerator<T> CrossLink.CircularBuffer< T >.GetEnumerator ( )

Returns an enumerator that iterates through this buffer.

Returns
An enumerator that can be used to iterate this collection.

◆ PopBack()

void CrossLink.CircularBuffer< T >.PopBack ( )

Removes the element at the back of the buffer. Decreasing the Buffer size by 1.

◆ PopFront()

void CrossLink.CircularBuffer< T >.PopFront ( )

Removes the element at the front of the buffer. Decreasing the Buffer size by 1.

◆ PushBack()

void CrossLink.CircularBuffer< T >.PushBack ( item)

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
itemItem to push to the back of the buffer

◆ PushFront()

void CrossLink.CircularBuffer< T >.PushFront ( item)

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
itemItem to push to the front of the buffer

◆ ToArray()

T [] CrossLink.CircularBuffer< 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)

Returns
A new array with a copy of the buffer contents.

◆ ToArraySegments()

IList<ArraySegment<T> > CrossLink.CircularBuffer< 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.

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.

Property Documentation

◆ Capacity

int CrossLink.CircularBuffer< T >.Capacity
get

Maximum capacity of the buffer. Elements pushed into the buffer after maximum capacity is reached (IsFull = true), will remove an element.

◆ IsEmpty

bool CrossLink.CircularBuffer< T >.IsEmpty
get

True if has no elements.

◆ IsFull

bool CrossLink.CircularBuffer< T >.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.

◆ Size

int CrossLink.CircularBuffer< T >.Size
get

Current buffer size (the number of elements that the buffer has).

◆ this[int index]

T CrossLink.CircularBuffer< T >.this[int index]
getset

Index access to elements in buffer. Index does not loop around like when adding elements, valid interval is [0;Size[

Parameters
indexIndex of element to access.
Exceptions
IndexOutOfRangeExceptionThrown when index is outside of [; Size[ interval.