Table of Contents

Class DynamicArray<T>

Namespace
Misaki.HighPerformance.Collections
Assembly
Misaki.HighPerformance.dll

A dynamically sized array that grows as elements are added and exposes span access to the active range.

public class DynamicArray<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable

Type Parameters

T

Represents a type that can be stored in the dynamic array.

Inheritance
DynamicArray<T>
Implements
Inherited Members

Constructors

DynamicArray(int)

Initializes a new instance of DynamicArray<T> with the specified initial capacity.

public DynamicArray(int initialCapacity = 4)

Parameters

initialCapacity int

The initial size of the backing array.

Properties

Capacity

Gets or sets the allocated capacity of the underlying storage.

public int Capacity { get; set; }

Property Value

int

Count

Gets the number of elements currently stored in the array.

public int Count { get; }

Property Value

int

IsReadOnly

Gets a value indicating whether the collection is read-only.

public bool IsReadOnly { get; }

Property Value

bool

this[int]

Gets a reference to the element at the specified index.

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

Parameters

index int

Property Value

T

this[uint]

Gets a reference to the element at the specified index.

public ref T this[uint index] { get; }

Parameters

index uint

Property Value

T

Methods

Add(T)

Adds an element to the end of the array.

public void Add(T item)

Parameters

item T

The element to add.

AsSpan()

Returns a span over the active portion of the array.

public Span<T> AsSpan()

Returns

Span<T>

A span containing the stored elements.

Clear()

Removes all elements from the array.

public void Clear()

Contains(T)

Determines whether the specified item exists in the array.

public bool Contains(T item)

Parameters

item T

The item to locate.

Returns

bool

True if the item is found; otherwise, false.

CopyTo(T[], int)

Copies the active elements to the specified array starting at the given index.

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

Parameters

array T[]

The destination array.

arrayIndex int

The index in the destination array at which copying begins.

GetEnumerator()

Returns an enumerator that iterates over the stored elements.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

An enumerator for the collection.

IndexOf(T)

Searches for the specified item and returns its zero-based index.

public int IndexOf(T item)

Parameters

item T

The item to locate.

Returns

int

The zero-based index of the item if found; otherwise, -1.

Insert(int, T)

Inserts an element at the specified index.

public void Insert(int index, T item)

Parameters

index int

The position at which to insert the element.

item T

The element to insert.

Exceptions

ArgumentOutOfRangeException

Thrown when the index is outside the valid range.

Remove(T)

Removes the first occurrence of the specified item.

public bool Remove(T item)

Parameters

item T

The item to remove.

Returns

bool

True if the item was removed; otherwise, false.

RemoveAt(int)

Removes the element at the specified index.

public void RemoveAt(int index)

Parameters

index int

The index of the element to remove.

Exceptions

ArgumentOutOfRangeException

Thrown when the index is outside the valid range.