Table of Contents

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

list List<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

T

The 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

span ReadOnlySpan<T>

The read-only span from which to retrieve the element.

index int

The 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

T

The 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

span Span<T>

The span from which to retrieve the element.

index int

The zero-based index of the element to retrieve.

Returns

T

A reference to the element at the specified index in the span.

Type Parameters

T

The 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

list List<T>

The list from which to remove the element. Cannot be null.

index int

The 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

T

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