Api Sandbox Utility CircularBuffer<T>
class

CircularBuffer<T>

public class CircularBuffer<T>

Circular buffer, push pop and index access is always O(1).

Constructors

CircularBuffer<T>(Int32 capacity)

Initializes a new instance of the CircularBuffer`1 class.

capacity — Buffer capacity. Must be positive.
CircularBuffer<T>(Int32 capacity, T[] items)

Properties

Name Type Description
Capacity Int32 Maximum capacity of the buffer. Elements pushed into the buffer after maximum capacity is reached (IsFull = true), will remove an element.
IsFull Boolean 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.
IsEmpty Boolean True if has no elements.
Size Int32 Current buffer size (the number of elements that the buffer has).
Item T

Methods

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.
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.
Void PushBack(T item)
Void PushFront(T item)
Void PopBack()

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

Void PopFront()

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

Void Clear()

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

NotImplementedException
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.
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. Fast: does not copy the array elements. Useful for methods like Send(IList&lt;ArraySegment&lt;Byte&gt;&gt;). Segments may be empty.

returns — An IList with 2 segments corresponding to the buffer content.
Enumerator<T> GetEnumerator()

Returns a struct-based enumerator that iterates through this buffer without any heap allocation. The compiler's duck-typing for will prefer this overload over the interface methods, so foreach (var x in buffer) is zero-alloc.

Assembly: Sandbox.System Namespace: Sandbox.Utility Full Name: Sandbox.Utility.CircularBuffer<T>