Show / Hide Table of Contents

Class CircularBuffer<T>

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.

Inheritance
System.Object
CircularBuffer<T>
Implements
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: HurricaneVR.Framework.Shared.Utilities
Assembly: HurricaneVR.Framework.dll
Syntax
public class CircularBuffer<T> : IEnumerable<T>, IEnumerable
Type Parameters
Name Description
T

Constructors

| Improve this Doc View Source

CircularBuffer(Int32)

Declaration
public CircularBuffer(int capacity)
Parameters
Type Name Description
System.Int32 capacity
| Improve this Doc View Source

CircularBuffer(Int32, T[])

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

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

| Improve this Doc View Source

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
System.Int32
| Improve this Doc View Source

IsEmpty

Declaration
public bool IsEmpty { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

IsFull

Declaration
public bool IsFull { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

Item[Int32]

Declaration
public T this[int index] { get; set; }
Parameters
Type Name Description
System.Int32 index
Property Value
Type Description
T
| Improve this Doc View Source

Size

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

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

Methods

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

Item to push to the back of the buffer

| Improve this Doc View Source

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

Item to push to the front of the buffer

| Improve this Doc View Source

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.

| Improve this Doc View Source

GetEnumerator()

Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<T>
| Improve this Doc View Source

PopBack()

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

Declaration
public void PopBack()
| Improve this Doc View Source

PopFront()

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

Declaration
public void PopFront()
| Improve this Doc View Source

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.

Explicit Interface Implementations

| Improve this Doc View Source

IEnumerable.GetEnumerator()

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator

Implements

System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX