Table of Contents

Class RingBuffer<T>

Namespace
Uncreated.Warfare.Util.List
Assembly
Uncreated.Warfare.dll

Fixed size first-in-last-out buffer.

public class RingBuffer<T> : IList<T>, ICollection<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable

Type Parameters

T
Inheritance
RingBuffer<T>
Implements
Inherited Members
Extension Methods

Constructors

RingBuffer(int)

public RingBuffer(int capacity)

Parameters

capacity int

RingBuffer(int, IEqualityComparer<T>)

public RingBuffer(int capacity, IEqualityComparer<T> equalityComparer)

Parameters

capacity int
equalityComparer IEqualityComparer<T>

Properties

Capacity

Number of elements that can fit in the buffer.

public int Capacity { get; set; }

Property Value

int

Count

Gets the number of elements contained in the ICollection<T>.

public int Count { get; }

Property Value

int

The number of elements contained in the ICollection<T>.

this[int]

Gets or sets the element at the specified index.

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

Parameters

index int

The zero-based index of the element to get or set.

Property Value

T

The element at the specified index.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in the IList<T>.

NotSupportedException

The property is set and the IList<T> is read-only.

UnderlyingIndex

public int UnderlyingIndex { get; }

Property Value

int

Version

public int Version { get; }

Property Value

int

Methods

Add(T)

Add a new value to the buffer.

public void Add(T value)

Parameters

value T

Clear()

Removes all items from the ICollection<T>.

public void Clear()

Exceptions

NotSupportedException

The ICollection<T> is read-only.

Contains(T)

Determines whether the ICollection<T> contains a specific value.

public bool Contains(T value)

Parameters

value T

Returns

bool

true if item is found in the ICollection<T>; otherwise, false.

CopyTo(int, Span<T>)

Copy as many elements as possible from this buffer to a span, skipping the first index elements.

public void CopyTo(int index, Span<T> span)

Parameters

index int
span Span<T>

CopyTo(int, T[], int, int)

Copy as many elements as possible up to count from this buffer to a array, starting at a given arrayIndex, skipping the first index elements.

public void CopyTo(int index, T[] array, int arrayIndex, int count)

Parameters

index int
array T[]
arrayIndex int
count int

CopyTo(Span<T>)

Copy as many elements as possible from this buffer to a span.

public void CopyTo(Span<T> span)

Parameters

span Span<T>

CopyTo(T[])

Copy as many elements as possible from this buffer to an array.

public void CopyTo(T[] array)

Parameters

array T[]

CopyTo(T[], int)

Copy as many elements as possible from this buffer to an array, starting at a given arrayIndex.

public void CopyTo(T[] array, int arrayIndex)

Parameters

array T[]
arrayIndex int

GetEnumerator()

Returns an enumerator that iterates through the collection.

public RingBuffer<T>.Enumerator GetEnumerator()

Returns

RingBuffer<T>.Enumerator

An enumerator that can be used to iterate through the collection.

IndexOf(T)

Determines the index of a specific item in the IList<T>.

public int IndexOf(T value)

Parameters

value T

Returns

int

The index of item if found in the list; otherwise, -1.

IndexOfIntl(T)

public int IndexOfIntl(T value)

Parameters

value T

Returns

int

Insert(int, T)

Insert an item at the specified index, dropping the oldest element if necessary.

public void Insert(int index, T item)

Parameters

index int
item T

Exceptions

ArgumentOutOfRangeException

Remove(T)

Removes the first occurrence of a specific object from the ICollection<T>.

public bool Remove(T value)

Parameters

value T

Returns

bool

true if item was successfully removed from the ICollection<T>; otherwise, false. This method also returns false if item is not found in the original ICollection<T>.

Exceptions

NotSupportedException

The ICollection<T> is read-only.

RemoveAt(int)

Remove an item at the specified index.

public void RemoveAt(int index)

Parameters

index int

Exceptions

ArgumentOutOfRangeException

ToArray()

Create a new array with the data on this buffer.

public T[] ToArray()

Returns

T[]

UnsafeGetUnderlyingArray()

public T?[] UnsafeGetUnderlyingArray()

Returns

T[]