API ReferenceSandbox.Utility

CircularBuffer<T>class

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

objectCircularBuffer<T>
Namespace
Sandbox.Utility
Assembly
Sandbox.System
Declaration
public class Sandbox.Utility.CircularBuffer<T>

Constructors2

Showing 2 constructors

Methods10

Showing 10 methods

public T Back()PUBLIC

Element at the back of the buffer - this[Size - 1].

Returns:TThe value of the element of type T at the back of the buffer.

public void Clear()PUBLIC

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

Returns:void

Exceptions

ExceptionCondition
NotImplementedException

public T Front()PUBLIC

Element at the front of the buffer - this[0].

Returns:TThe value of the element of type T at the front of the buffer.

public Sandbox.Utility.CircularBuffer`1.Enumerator<T> GetEnumerator()PUBLIC

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.

Returns:Enumerator<T>

public void PopBack()PUBLIC

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

Returns:void

public void PopFront()PUBLIC

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

Returns:void

public void PushBack(T item)PUBLIC

ParameterTypeDescription
itemT
Returns:void

public void PushFront(T item)PUBLIC

ParameterTypeDescription
itemT
Returns:void

public T[] ToArray()PUBLIC

Copies the buffer contents to an array, according to the logical contents of the buffer (i.e. independent of the internal order/contents)

Returns:T[]A new array with a copy of the buffer contents.

public System.Collections.Generic.IEnumerable`1<System.ArraySegment`1<T>> ToArraySegments()PUBLIC

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>)`. Segments may be empty.

Returns:IEnumerable<ArraySegment<T>>An IList with 2 segments corresponding to the buffer content.

Properties5

Showing 5 properties

public int Sandbox.Utility.CircularBuffer<T>.Capacity { get; set; }PUBLICGETSET

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

Returns:int

public bool Sandbox.Utility.CircularBuffer<T>.IsEmpty { get; set; }PUBLICGETSET

True if has no elements.

Returns:bool

public bool Sandbox.Utility.CircularBuffer<T>.IsFull { get; set; }PUBLICGETSET

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.

Returns:bool

public T Sandbox.Utility.CircularBuffer<T>.Item { get; set; }PUBLICGETSET

Returns:T

public int Sandbox.Utility.CircularBuffer<T>.Size { get; set; }PUBLICGETSET

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

Returns:int

On this page