Skip to main content

Class RingBuffer<T>

Inheritance
System.Object
Inherited Members
Show
Syntax
public class RingBuffer<T>
Type Parameters
NameDescription
T

Constructors

RingBuffer(Int32, ILogger)

Declaration
public RingBuffer(int bitCount, ILogger logger)
Parameters
TypeNameDescription
System.Int32bitCount
UnityEngine.ILoggerlogger

RingBuffer(Int32, IEqualityComparer<T>, ILogger)

Declaration
public RingBuffer(int bitCount, IEqualityComparer<T> comparer, ILogger logger)
Parameters
TypeNameDescription
System.Int32bitCount
System.Collections.Generic.IEqualityComparer<T>comparer
UnityEngine.ILoggerlogger

Fields

Sequencer

Declaration
public readonly Sequencer Sequencer

Properties

Read

Declaration
public uint Read { get; }

Write

Declaration
public uint Write { get; }

Count

Number of non-null items in buffer NOTE: this is not distance from read to write

Declaration
public int Count { get; }

Capacity

Declaration
public int Capacity { get; }

Item[UInt32]

Declaration
public T this[uint index] { get; }

Item[Int32]

Declaration
public T this[int index] { get; }

IsFull

Declaration
public bool IsFull { get; }

Methods

DistanceToRead(UInt32)

Declaration
public long DistanceToRead(uint from)
Parameters
TypeNameDescription
System.UInt32from
Returns
TypeDescription
System.Int64

Enqueue(T)

Declaration
public uint Enqueue(T item)
Parameters
TypeNameDescription
Titem
Returns
TypeDescription
System.UInt32sequence of written item

TryPeak(out T)

Tries to read the item at read index same as but does not remove the item after reading it

Declaration
public bool TryPeak(out T item)
Parameters
TypeNameDescription
Titem
Returns
TypeDescription
System.Booleantrue if item exists, or false if it is missing

Exists(UInt32)

Does item exist at index Index will be moved into bounds

Declaration
public bool Exists(uint index)
Parameters
TypeNameDescription
System.UInt32index
Returns
TypeDescription
System.Booleantrue if item exists, or false if it is missing

RemoveNext()

Removes the item at read index and increments read index can be used after to do the same as

Declaration
public void RemoveNext()

Dequeue()

Removes next item and increments read index Assumes next items exists, best to use this with

Declaration
public T Dequeue()
Returns
TypeDescription
T

TryDequeue(out T)

Tries to remove the item at read index

Declaration
public bool TryDequeue(out T item)
Parameters
TypeNameDescription
Titem
Returns
TypeDescription
System.Booleantrue if item exists, or false if it is missing

InsertAt(UInt32, T)

Declaration
public void InsertAt(uint index, T item)
Parameters
TypeNameDescription
System.UInt32index
Titem

RemoveAt(UInt32)

Declaration
public void RemoveAt(uint index)
Parameters
TypeNameDescription
System.UInt32index

MoveReadToNextNonEmpty()

Moves read index to next non empty position this is useful when removing items from buffer in random order. Will stop when write == read, or when next buffer item is not empty

Declaration
public void MoveReadToNextNonEmpty()

MoveReadOne()

Moves read 1 index

Declaration
public void MoveReadOne()

ClearAndRelease(Action<T>)

Declaration
public void ClearAndRelease(Action<T> releaseItem)
Parameters
TypeNameDescription
System.Action<T>releaseItem