Show / Hide Table of Contents

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.

Inheritance
object
CircularArray<T>
Implements
IList<T>
ICollection<T>
IReadOnlyList<T>
IReadOnlyCollection<T>
IEnumerable<T>
IEnumerable
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
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 Source

CircularArray()

Creates an empty CircularArray<T> with a small default capacity.

Declaration
public CircularArray()
View Source

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
View Source

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
View Source

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
View Source

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
View Source

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
View Source

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.

View Source

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 Source

Capacity

The number of elements the backing array can hold before it needs to grow.

Declaration
public int Capacity { get; }
Property Value
Type Description
int
View Source

Count

The number of elements currently stored.

Declaration
public int Count { get; }
Property Value
Type Description
int
View Source

IsReadOnly

Declaration
public bool IsReadOnly { get; }
Property Value
Type Description
bool
View Source

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 [0, Count).

Property Value
Type Description
T
Exceptions
Type Condition
IndexOutOfRangeException

index is negative or not less than Count.

Methods

View Source

Add(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.

View Source

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.

View Source

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.

View Source

Clear()

Removes all elements. This does not shrink the backing array.

Declaration
public void Clear()
View Source

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 T.

Returns
Type Description
bool
View Source

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 arrayIndex.

int arrayIndex

The index in array to start writing at.

View Source

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
View Source

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.

View Source

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 T.

Returns
Type Description
int

The zero-based logical index of the first matching element, or -1 if none is found.

View Source

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 [0, Count]; Count appends.

T item

The value to insert.

Exceptions
Type Condition
IndexOutOfRangeException

index is negative or greater than Count.

View Source

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 [0, Count]; Count appends.

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

index is negative or greater than Count.

View Source

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 [0, Count]; Count appends.

ReadOnlySpan<T> items

The elements to insert.

Exceptions
Type Condition
IndexOutOfRangeException

index is negative or greater than Count.

View Source

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 T.

Returns
Type Description
bool

true if a matching element was found and removed; otherwise false.

View Source

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 [0, Count).

Exceptions
Type Condition
IndexOutOfRangeException

index is negative or not less than Count.

View Source

ShrinkToFit()

Resizes the array to that the data fits perfectly into it.

Declaration
public void ShrinkToFit()

Implements

IList<T>
ICollection<T>
IReadOnlyList<T>
IReadOnlyCollection<T>
IEnumerable<T>
IEnumerable
  • View Source
In this article
Back to top Generated by DocFX