Class RingBuffer<T>
Writes values to a collection of a set size, overwriting old values as needed.
Inheritance
Implements
Inherited Members
Namespace: GameKit.Dependencies.Utilities.Types
Assembly: GameKit.Dependencies.dll
Syntax
public class RingBuffer<T> : IEnumerable<T>, IEnumerable
Type Parameters
Name | Description |
---|---|
T |
Constructors
RingBuffer()
Initializes with default capacity.
Declaration
public RingBuffer()
RingBuffer(Int32)
Initializes with a set capacity.
Declaration
public RingBuffer(int capacity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | capacity | Size to initialize the collection as. This cannot be changed after initialized. |
Fields
Capacity
Maximum size of the collection.
Declaration
public int Capacity
Field Value
Type | Description |
---|---|
System.Int32 |
Collection
Collection being used.
Declaration
public T[] Collection
Field Value
Type | Description |
---|---|
T[] |
DEFAULT_CAPACITY
Default capacity when none is psecified.
Declaration
public const int DEFAULT_CAPACITY = 60
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
Count
Number of entries currently written.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Initialized
True if initialized.
Declaration
public bool Initialized { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Item[Int32]
Returns value in actual index as it relates to simulated index.
Declaration
public T this[int simulatedIndex] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | simulatedIndex | Simulated index to return. A value of 0 would return the first simulated index in the collection. |
Property Value
Type | Description |
---|---|
T |
WriteIndex
Current write index of the collection.
Declaration
public int WriteIndex { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
Add(T)
Adds an entry to the collection, returning a replaced entry.
Declaration
public T Add(T data)
Parameters
Type | Name | Description |
---|---|---|
T | data | Data to add. |
Returns
Type | Description |
---|---|
T | Replaced entry. Value will be default if no entry was replaced. |
Clear()
Clears the collection to default values and resets indexing.
Declaration
public void Clear()
GetEnumerator()
Returns Enumerator for the collection.
Declaration
public RingBuffer<T>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
RingBuffer.Enumerator<> |
Initialize()
Initializes with default capacity.
Declaration
public void Initialize()
Initialize(Int32)
Initializes the collection at length.
Declaration
public void Initialize(int capacity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | capacity | Size to initialize the collection as. This cannot be changed after initialized. |
Insert(Int32, T)
Inserts an entry into the collection. This is can be an expensive operation on larger buffers.
Declaration
public T Insert(int simulatedIndex, T data)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | simulatedIndex | Simulated index to return. A value of 0 would return the first simulated index in the collection. |
T | data | Data to insert. |
Returns
Type | Description |
---|---|
T |
RemoveRange(Boolean, Int32)
Removes values from the simulated start of the collection.
Declaration
public void RemoveRange(bool fromStart, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | fromStart | True to remove from the start, false to remove from the end. |
System.Int32 | length | Number of entries to remove. |
Reset()
Resets the collection without clearing.
Declaration
[Obsolete("This method no longer functions. Use Clear() instead.")]
public void Reset()
Explicit Interface Implementations
IEnumerable<T>.GetEnumerator()
Declaration
IEnumerator<T> IEnumerable<T>.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<T> |
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |