Class CollectionUtility
- Namespace
- Misaki.HighPerformance.Utilities
- Assembly
- Misaki.HighPerformance.dll
public static class CollectionUtility
- Inheritance
-
CollectionUtility
- Inherited Members
Methods
AsSpan<T>(List<T>?)
Creates a span over the elements of the specified list.
public static Span<T> AsSpan<T>(this List<T>? list)
Parameters
listList<T>The list whose elements the span will cover. Can be null.
Returns
- Span<T>
A span over the elements of the list, or an empty span if the list is null or empty.
Type Parameters
TThe type of elements in the list.
Remarks
The span will become invalid if the list is modified (e.g., elements are added or removed).
GetElementUnsafe<T>(ReadOnlySpan<T>, int)
Returns a read-only reference to the element at the specified index within the given span without performing bounds checking.
public static ref readonly T GetElementUnsafe<T>(this ReadOnlySpan<T> span, int index)
Parameters
spanReadOnlySpan<T>The read-only span from which to retrieve the element.
indexintThe zero-based index of the element to retrieve.
Returns
- T
A read-only reference to the element at the specified index in the span.
Type Parameters
TThe type of elements contained in the span.
GetElementUnsafe<T>(Span<T>, int)
Returns a reference to the element at the specified index within the given span without performing bounds checking.
public static ref T GetElementUnsafe<T>(this Span<T> span, int index)
Parameters
spanSpan<T>The span from which to retrieve the element.
indexintThe zero-based index of the element to retrieve.
Returns
- T
A reference to the element at the specified index in the span.
Type Parameters
TThe type of elements contained in the span.
RemoveAndSwapBack<T>(List<T>, int)
Removes the element at the specified index from the list by replacing it with the last element, then removing the last element. This operation does not preserve the order of elements.
public static bool RemoveAndSwapBack<T>(this List<T> list, int index)
Parameters
listList<T>The list from which to remove the element. Cannot be null.
indexintThe zero-based index of the element to remove. Must be within the bounds of the list.
Returns
- bool
True if the element was successfully removed; otherwise, false.
Type Parameters
TThe type of elements in the list.
Exceptions
- ArgumentOutOfRangeException
Thrown if index is less than 0 or greater than or equal to the number of elements in the list.