Class RingBuffer<T>
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
-
IList<T>ICollection<T>IEnumerable<T>
- Inherited Members
- Extension Methods
Constructors
RingBuffer(int)
public RingBuffer(int capacity)
Parameters
capacityint
RingBuffer(int, IEqualityComparer<T>)
public RingBuffer(int capacity, IEqualityComparer<T> equalityComparer)
Parameters
capacityintequalityComparerIEqualityComparer<T>
Properties
Capacity
Number of elements that can fit in the buffer.
public int Capacity { get; set; }
Property Value
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
indexintThe zero-based index of the element to get or set.
Property Value
- T
The element at the specified index.
Exceptions
- ArgumentOutOfRangeException
indexis 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
Version
public int Version { get; }
Property Value
Methods
Add(T)
Add a new value to the buffer.
public void Add(T value)
Parameters
valueT
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
valueT
Returns
- bool
true if
itemis 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
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
CopyTo(Span<T>)
Copy as many elements as possible from this buffer to a span.
public void CopyTo(Span<T> span)
Parameters
spanSpan<T>
CopyTo(T[])
Copy as many elements as possible from this buffer to an array.
public void CopyTo(T[] array)
Parameters
arrayT[]
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
arrayT[]arrayIndexint
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
valueT
Returns
- int
The index of
itemif found in the list; otherwise, -1.
IndexOfIntl(T)
public int IndexOfIntl(T value)
Parameters
valueT
Returns
Insert(int, T)
Insert an item at the specified index, dropping the oldest element if necessary.
public void Insert(int index, T item)
Parameters
indexintitemT
Exceptions
Remove(T)
Removes the first occurrence of a specific object from the ICollection<T>.
public bool Remove(T value)
Parameters
valueT
Returns
- bool
true if
itemwas successfully removed from the ICollection<T>; otherwise, false. This method also returns false ifitemis 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
indexint
Exceptions
ToArray()
Create a new array with the data on this buffer.
public T[] ToArray()
Returns
- T[]
UnsafeGetUnderlyingArray()
public T?[] UnsafeGetUnderlyingArray()
Returns
- T[]