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
TRepresents a type that can be stored in the dynamic array.
- Inheritance
-
DynamicArray<T>
- Implements
-
IList<T>ICollection<T>IEnumerable<T>
- Inherited Members
Constructors
DynamicArray(int)
Initializes a new instance of DynamicArray<T> with the specified initial capacity.
public DynamicArray(int initialCapacity = 4)
Parameters
initialCapacityintThe 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
Count
Gets the number of elements currently stored in the array.
public int Count { get; }
Property Value
IsReadOnly
Gets a value indicating whether the collection is read-only.
public bool IsReadOnly { get; }
Property Value
this[int]
Gets a reference to the element at the specified index.
public ref T this[int index] { get; }
Parameters
indexint
Property Value
- T
this[uint]
Gets a reference to the element at the specified index.
public ref T this[uint index] { get; }
Parameters
indexuint
Property Value
- T
Methods
Add(T)
Adds an element to the end of the array.
public void Add(T item)
Parameters
itemTThe 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
itemTThe 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
arrayT[]The destination array.
arrayIndexintThe 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
itemTThe 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
indexintThe position at which to insert the element.
itemTThe 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
itemTThe 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
indexintThe index of the element to remove.
Exceptions
- ArgumentOutOfRangeException
Thrown when the index is outside the valid range.