CircularArray<T>

public class CircularArray<T> : IEnumerable<T>
Represents a threadsafe circular array. A circular array has a maximum length, but items can always be added to it efficiently. Once the capacity has been reached, newly added items override the oldest items.
TArray type.

Constructors

CircularArray

#
public CircularArray(int capacity)
Create a new circular array.
capacity (int)Maximum capacity.

Properties

Capacity

#
public int Capacity { get; }
Gets the maximum capacity of this array.

Count

#
public int Count { get; }
Gets the number of items stored in the array.

ItemsNewest

#
public IEnumerable<T> ItemsNewest { get; }
Enumerate over all items, starting with the newest ones.

ItemsOldest

#
public IEnumerable<T> ItemsOldest { get; }
Enumerate over all items, starting with the oldest ones.

Newest

#
public T Newest { get; }
Gets the newest item added to the array. If the array contains no items, default(T) is returned.

Oldest

#
public T Oldest { get; }
Gets the oldest item still in the array. If the array contains no items, default(T) is returned.

Methods

Add

#
public void Add(T item)
Add an item to the array.
item (T)Item to add.

Clear

#
public void Clear()
Clear all items in the array.

GetEnumerator

#
public IEnumerator<T> GetEnumerator()
Enumerate over all items in the circular array.
Explicit

IEnumerable.GetEnumerator

#
IEnumerator IEnumerable.GetEnumerator()

ToArray

#
public T[] ToArray()
Create a correctly sized, correctly ordered array representing the current state of the circular array. The items in the returned array are sorted from oldest to newest.
Array of T.