Class CircularArray<T>
A resizable, array-backed list that stores its elements in a ring buffer (a "deque"-like structure) rather than always starting at index 0. This makes both ends of the collection cheap to grow/shrink from, and Insert(int, T) / RemoveAt(int) only need to shift whichever side of the target index is smaller, instead of always shifting everything after it as a plain array-backed list would.
Inherited Members
Namespace: FFmpeg.Collections
Assembly: FFmpeg.dll
Syntax
public class CircularArray<T> : IList<T>, ICollection<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
| Name | Description |
|---|---|
| T | The type of elements stored in the collection. |
Constructors
View SourceCircularArray()
Creates an empty CircularArray<T> with a small default capacity.
Declaration
public CircularArray()
CircularArray(ICollection<T>)
Creates a CircularArray<T> containing a copy of list's elements.
Declaration
public CircularArray(ICollection<T> list)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection<T> | list |
CircularArray(IEnumerable<T>)
Creates a CircularArray<T> containing a copy of list's elements.
The sequence is consumed lazily via repeated Add(T) calls, since its length isn't
known up front.
Declaration
public CircularArray(IEnumerable<T> list)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | list |
CircularArray(IList<T>)
Creates a CircularArray<T> containing a copy of list's elements.
Declaration
public CircularArray(IList<T> list)
Parameters
| Type | Name | Description |
|---|---|---|
| IList<T> | list |
CircularArray(IReadOnlyList<T>)
Creates a CircularArray<T> containing a copy of list's elements.
Declaration
public CircularArray(IReadOnlyList<T> list)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<T> | list |
CircularArray(List<T>)
Creates a CircularArray<T> containing a copy of list's elements.
Declaration
public CircularArray(List<T> list)
Parameters
| Type | Name | Description |
|---|---|---|
| List<T> | list |
CircularArray(int)
Creates an empty CircularArray<T> with the given initial capacity.
Declaration
public CircularArray(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| int | capacity | The number of elements the backing array can hold before it needs to grow. |
CircularArray(ReadOnlySpan<T>)
Creates a CircularArray<T> containing a copy of list's elements.
Declaration
public CircularArray(ReadOnlySpan<T> list)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | list |
Properties
View SourceCapacity
The number of elements the backing array can hold before it needs to grow.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| int |
Count
The number of elements currently stored.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsReadOnly
Declaration
public bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| bool |
this[int]
Gets a reference to the element at the given logical index, allowing
both reading and in-place mutation (e.g. array[i]++).
Declaration
public ref T this[int index] { get; }
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | A zero-based logical index in the range |
Property Value
| Type | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException |
|
Methods
View SourceAdd(T)
Appends item to the end of the collection, growing the backing array
first if it's already full.
Declaration
public void Add(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The value to append. |
AddRange(IEnumerable<T>)
Adds the elements of items, in order at the end of the list.
Declaration
public void AddRange(IEnumerable<T> items)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | items | The elements to insert. |
AddRange(ReadOnlySpan<T>)
Adds the elements of items, in order at the end of the list.
Declaration
public void AddRange(ReadOnlySpan<T> items)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | items | The elements to insert. |
Clear()
Removes all elements. This does not shrink the backing array.
Declaration
public void Clear()
Contains(T)
Determines whether item is present in the collection.
Declaration
public bool Contains(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The value to locate, compared using the default equality comparer for |
Returns
| Type | Description |
|---|---|
| bool |
CopyTo(T[], int)
Copies all elements, in logical order, into array starting at arrayIndex.
Declaration
public void CopyTo(T[] array, int arrayIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The destination array. Must have room for Count elements starting at |
| int | arrayIndex | The index in |
GetEnumerator()
Returns a struct enumerator over the elements in logical order. Prefer iterating via
foreach directly (rather than through IEnumerable<T>) to avoid boxing.
Declaration
public CircularArray<T>.CircularArrayEnumerator GetEnumerator()
Returns
| Type | Description |
|---|---|
| CircularArray<T>.CircularArrayEnumerator |
GetSpans(out Span<T>, out Span<T>)
Returns the live elements as one or two contiguous Span<T> slices over the
backing array, in logical order. Two spans are returned when the logical range wraps past
the end of the backing array; second is empty otherwise.
Declaration
public void GetSpans(out Span<T> first, out Span<T> second)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | first | The first (and possibly only) contiguous slice of live elements. |
| Span<T> | second | The remaining live elements after the wrap point, or empty if there is no wrap. |
IndexOf(T)
Searches for item and returns its logical index, or -1 if not found.
Declaration
public int IndexOf(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The value to locate, compared using the default equality comparer for |
Returns
| Type | Description |
|---|---|
| int | The zero-based logical index of the first matching element, or -1 if none is found. |
Insert(int, T)
Inserts item at the given logical index, shifting later elements
(or earlier elements, whichever is fewer) to make room.
Declaration
public void Insert(int index, T item)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The logical index to insert at. Valid range is |
| T | item | The value to insert. |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException |
|
InsertRange(int, IEnumerable<T>)
Inserts the elements of data, in order, starting at the given logical index.
Declaration
public void InsertRange(int index, IEnumerable<T> data)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The logical index to insert at. Valid range is |
| IEnumerable<T> | data | The elements to insert. If this isn't a T[], List<T>, or ICollection<T>, it is fully enumerated and buffered first, since the length must be known before any shifting happens. |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException |
|
InsertRange(int, ReadOnlySpan<T>)
Inserts the elements of items, in order, starting at the given logical index.
Declaration
public void InsertRange(int index, ReadOnlySpan<T> items)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The logical index to insert at. Valid range is |
| ReadOnlySpan<T> | items | The elements to insert. |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException |
|
Remove(T)
Removes the first occurrence of item, if present.
Declaration
public bool Remove(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The value to remove, compared using the default equality comparer for |
Returns
| Type | Description |
|---|---|
| bool |
|
RemoveAt(int)
Removes the element at the given logical index, shifting whichever side of the split
(elements before or after index) is smaller to close the gap. If the
collection becomes sufficiently sparse, the backing array is also shrunk to reclaim memory.
Declaration
public void RemoveAt(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The logical index of the element to remove. Valid range is |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException |
|
ShrinkToFit()
Resizes the array to that the data fits perfectly into it.
Declaration
public void ShrinkToFit()