VisioForge (c) 2025

Search Results for

    Class CircularBuffer<T>

    Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy.

    Inheritance
    object
    CircularBuffer<T>
    Implements
    IEnumerable<T>
    IEnumerable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: VisioForge.Core.Helpers
    Assembly: VisioForge.Core.dll
    Syntax
    public class CircularBuffer<T> : IEnumerable<T>, IEnumerable
    Type Parameters
    Name Description
    T

    Constructors

    CircularBuffer(int)

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

    Declaration
    public CircularBuffer(int capacity)
    Parameters
    Type Name Description
    int capacity

    Buffer capacity. Must be positive.

    CircularBuffer(int, T[])

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

    Declaration
    public CircularBuffer(int capacity, T[] items)
    Parameters
    Type Name Description
    int 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

    Capacity

    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
    int

    IsEmpty

    True if has no elements.

    Declaration
    public bool IsEmpty { get; }
    Property Value
    Type Description
    bool

    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.

    Declaration
    public bool IsFull { get; }
    Property Value
    Type Description
    bool

    this[int]

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

    Declaration
    public T this[int index] { get; set; }
    Parameters
    Type Name Description
    int index

    Index of element to access.

    Property Value
    Type Description
    T
    Exceptions
    Type Condition
    IndexOutOfRangeException

    Thrown when index is outside of [; Size[ interval.

    Size

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

    Declaration
    public int Size { get; }
    Property Value
    Type Description
    int

    Methods

    Back()

    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.

    Clear()

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

    Declaration
    public void Clear()
    Exceptions
    Type Condition
    NotImplementedException

    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()

    Returns an enumerator that iterates through this buffer.

    Declaration
    public IEnumerator<T> GetEnumerator()
    Returns
    Type Description
    IEnumerator<T>

    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.

    Declaration
    public void PopBack()

    PopFront()

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

    Declaration
    public void PopFront()

    PushBack(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 PushBack(T item)
    Parameters
    Type Name Description
    T item

    Item to push to the back of the buffer

    PushFront(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 PushFront(T item)
    Parameters
    Type Name Description
    T 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)

    Declaration
    public T[] ToArray()
    Returns
    Type Description
    T[]

    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.

    Declaration
    public IList<ArraySegment<T>> ToArraySegments()
    Returns
    Type Description
    IList<ArraySegment<T>>

    An IList with 2 segments corresponding to the buffer content.

    Implements

    IEnumerable<T>
    IEnumerable