Table of Contents

Struct RentedMemorySequenceSpan<T>

Namespace
LfrlAnvil.Memory
Assembly
LfrlAnvil.Core.dll

A lightweight slice of RentedMemorySequence<T>.

public readonly ref struct RentedMemorySequenceSpan<T>

Type Parameters

T

Element type.

Inherited Members

Properties

Empty

An empty sequence span.

public static RentedMemorySequenceSpan<T> Empty { get; }

Property Value

RentedMemorySequenceSpan<T>

this[int]

Gets or sets the element at the specified position in this span.

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

Parameters

index int

The zero-based index of the element to get or set.

Property Value

T

Exceptions

ArgumentOutOfRangeException

When index is less than 0 or greater than or equal to Length.

Length

Number of elements in this span.

public int Length { get; }

Property Value

int

Segments

Creates a new RentedMemorySequenceSegmentCollection<T> instance from this span.

public RentedMemorySequenceSegmentCollection<T> Segments { get; }

Property Value

RentedMemorySequenceSegmentCollection<T>

StartIndex

Index of the first element of a sequence included in this span.

public int StartIndex { get; }

Property Value

int

Methods

Clear()

Sets all elements to the default value in this span.

public void Clear()

Contains(T)

Checks whether or not the provided item exists in this span.

[Pure]
public bool Contains(T item)

Parameters

item T

Item to check.

Returns

bool

true when the provided item exists, otherwise false.

CopyFrom(ReadOnlySpan<T>)

Copies the provided span to this span.

public void CopyFrom(ReadOnlySpan<T> span)

Parameters

span ReadOnlySpan<T>

Copy source.

Remarks

Does nothing when this span has been returned to the pool.

Exceptions

ArgumentOutOfRangeException

When Length is less than length of the provided span.

CopyTo(RentedMemorySequenceSpan<T>)

Copies this span to the provided span.

public void CopyTo(RentedMemorySequenceSpan<T> span)

Parameters

span RentedMemorySequenceSpan<T>

Copy destination.

Exceptions

ArgumentOutOfRangeException

When Length is greater than length of the provided span.

CopyTo(Span<T>)

Copies this span to the provided span.

public void CopyTo(Span<T> span)

Parameters

span Span<T>

Copy destination.

Exceptions

ArgumentOutOfRangeException

When Length is greater than length of the provided span.

CopyTo(T[], int)

Copies this span to the provided array, starting from the given arrayIndex.

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

Parameters

array T[]

Copy destination.

arrayIndex int

Index of the destination array at which to start copying to.

Exceptions

ArgumentOutOfRangeException

When arrayIndex is less than 0 or greater than or equal to the length of the provided array or Length is greater than length of the provided array segment.

GetEnumerator()

Creates a new RentedMemorySequenceSpan<T>.Enumerator instance for this span.

[Pure]
public RentedMemorySequenceSpan<T>.Enumerator GetEnumerator()

Returns

RentedMemorySequenceSpan<T>.Enumerator

New RentedMemorySequenceSpan<T>.Enumerator instance.

GetRef(int)

Returns a reference to an element at the specified position.

[Pure]
public ref T GetRef(int index)

Parameters

index int

The zero-based index of the element reference to get.

Returns

T

Reference to an element at the specified position.

Exceptions

ArgumentOutOfRangeException

When index is less than 0 or greater than or equal to Length.

Set(int, T)

Sets an element at the specified position.

public void Set(int index, T item)

Parameters

index int

The zero-based index of the element to set.

item T

Element to set.

Exceptions

ArgumentOutOfRangeException

When index is less than 0 or greater than or equal to Length.

Slice(int)

Creates a new RentedMemorySequenceSpan<T> instance.

[Pure]
public RentedMemorySequenceSpan<T> Slice(int startIndex)

Parameters

startIndex int

Index of the first element that should be included in the slice.

Returns

RentedMemorySequenceSpan<T>

New RentedMemorySequenceSpan<T> instance.

Exceptions

ArgumentOutOfRangeException

When startIndex is less than 0 or is greater than or equal to Length.

Slice(int, int)

Creates a new RentedMemorySequenceSpan<T> instance.

[Pure]
public RentedMemorySequenceSpan<T> Slice(int startIndex, int length)

Parameters

startIndex int

Index of the first element that should be included in the slice.

length int

Length of the slice.

Returns

RentedMemorySequenceSpan<T>

New RentedMemorySequenceSpan<T> instance.

Exceptions

ArgumentOutOfRangeException

When startIndex is less than 0 or length is less than 0 or computed index of the last element in the slice is greater than or equal to Length.

Sort(Comparer<T>?)

Sorts elements in this span.

public void Sort(Comparer<T>? comparer = null)

Parameters

comparer Comparer<T>

Optional comparer to use for sorting elements.

Sort(Comparison<T>)

Sorts elements in this span.

public void Sort(Comparison<T> comparer)

Parameters

comparer Comparison<T>

Delegate used for sorting elements.

ToArray()

Creates a new Array instance from this span.

[Pure]
public T[] ToArray()

Returns

T[]

New Array instance.

ToString()

Returns a string representation of this RentedMemorySequenceSpan<T> instance.

[Pure]
public override string ToString()

Returns

string

String representation.