Class Span
Provides extension methods for type Span<T> and ReadOnlySpan<T>.
Inherited Members
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class Span
Methods
View SourceAdvance<T>(ref ReadOnlySpan<T>)
Takes the first element and adjusts the span.
Declaration
public static ref readonly T Advance<T>(this ref ReadOnlySpan<T> source)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | source |
Returns
| Type | Description |
|---|---|
| T | The reference to the first element in the span. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The source span is empty. |
Advance<T>(ref ReadOnlySpan<T>, int)
Takes the specified number of elements and adjusts the span.
Declaration
public static ReadOnlySpan<T> Advance<T>(this ref ReadOnlySpan<T> source, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | source | |
| int | count | The number of elements to take. |
Returns
| Type | Description |
|---|---|
| ReadOnlySpan<T> | The span containing |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
Advance<T>(ref Span<T>)
Takes the first element and adjusts the span.
Declaration
public static ref T Advance<T>(this ref Span<T> source)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | source |
Returns
| Type | Description |
|---|---|
| T | The reference to the first element in the span. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The source span is empty. |
Advance<T>(ref Span<T>, int)
Takes the specified number of elements and adjusts the span.
Declaration
public static Span<T> Advance<T>(this ref Span<T> source, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | source | |
| int | count | The number of elements to take. |
Returns
| Type | Description |
|---|---|
| Span<T> | The span containing |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
BitwiseCompare<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
Compares content of the two memory blocks identified by the given spans.
Declaration
public static int BitwiseCompare<T>(this ReadOnlySpan<T> x, ReadOnlySpan<T> y) where T : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | x | |
| ReadOnlySpan<T> | y | The second array to compare. |
Returns
| Type | Description |
|---|---|
| int | Comparison result. |
Type Parameters
| Name | Description |
|---|---|
| T |
BitwiseEquals<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
Determines whether two memory blocks identified by the given spans contain the same set of elements.
Declaration
public static bool BitwiseEquals<T>(this ReadOnlySpan<T> x, ReadOnlySpan<T> y) where T : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | x | |
| ReadOnlySpan<T> | y | The second memory span to compare. |
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T |
Remarks
This method performs bitwise equality between each pair of elements.
CheckMask<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
Determines whether the specified value satisfies the given mask.
Declaration
public static bool CheckMask<T>(this ReadOnlySpan<T> x, ReadOnlySpan<T> mask) where T : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | x | |
| ReadOnlySpan<T> | mask | The mask. |
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T |
Concat<T>(ReadOnlySpan<T>, ReadOnlySpan<T>, MemoryAllocator<T>?)
Concatenates memory blocks.
Declaration
public static MemoryOwner<T> Concat<T>(ReadOnlySpan<T> first, ReadOnlySpan<T> second, MemoryAllocator<T>? allocator = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | first | The first memory block. |
| ReadOnlySpan<T> | second | The second memory block. |
| MemoryAllocator<T> | allocator | The memory allocator used to allocate buffer for the result. |
Returns
| Type | Description |
|---|---|
| MemoryOwner<T> | The memory block containing elements from the specified two memory blocks. |
Type Parameters
| Name | Description |
|---|---|
| T |
Concat<T>(ReadOnlySpan<T>, ReadOnlySpan<T>, ReadOnlySpan<T>, MemoryAllocator<T>?)
Concatenates memory blocks.
Declaration
public static MemoryOwner<T> Concat<T>(ReadOnlySpan<T> first, ReadOnlySpan<T> second, ReadOnlySpan<T> third, MemoryAllocator<T>? allocator = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | first | The first memory block. |
| ReadOnlySpan<T> | second | The second memory block. |
| ReadOnlySpan<T> | third | The third memory block. |
| MemoryAllocator<T> | allocator | The memory allocator used to allocate buffer for the result. |
Returns
| Type | Description |
|---|---|
| MemoryOwner<T> | The memory block containing elements from the specified two memory blocks. |
Type Parameters
| Name | Description |
|---|---|
| T |
Copy<T>(ReadOnlySpan<T>, MemoryAllocator<T>?)
Creates buffered copy of the memory block.
Declaration
public static MemoryOwner<T> Copy<T>(this ReadOnlySpan<T> span, MemoryAllocator<T>? allocator = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | span | |
| MemoryAllocator<T> | allocator | Optional buffer allocator. |
Returns
| Type | Description |
|---|---|
| MemoryOwner<T> | The copy of the elements from the source span. |
Type Parameters
| Name | Description |
|---|---|
| T |
FirstOrNone<T>(ReadOnlySpan<T>, Predicate<T>?)
Returns the first element in a span that satisfies a specified condition.
Declaration
public static Optional<T> FirstOrNone<T>(this ReadOnlySpan<T> span, Predicate<T>? filter = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | span | |
| Predicate<T> | filter | A function to test each element for a condition. |
Returns
| Type | Description |
|---|---|
| Optional<T> | The first element in the span that matches to the specified filter; or None. |
Type Parameters
| Name | Description |
|---|---|
| T |
ForEach<T>(Span<T>, Action<LocalReference<T>, int>)
Iterates over elements of the span.
Declaration
public static void ForEach<T>(this Span<T> span, Action<LocalReference<T>, int> action)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | span | |
| Action<LocalReference<T>, int> | action | The action to be applied for each element of the span. |
Type Parameters
| Name | Description |
|---|---|
| T |
ForEach<T, TArg>(Span<T>, delegate*<ref T, TArg, void>, TArg)
Declaration
[CLSCompliant(false)]
public static void ForEach<T, TArg>(this Span<T> span, delegate*<ref T, TArg, void> action, TArg arg) where TArg : allows ref struct
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | span | |
| delegate*<ref T, TArg, void> | action | |
| TArg | arg |
Type Parameters
| Name | Description |
|---|---|
| T | |
| TArg |
IndexOf<T>(ReadOnlySpan<T>, T, int, delegate*<T, T, bool>)
Declaration
[CLSCompliant(false)]
public static int IndexOf<T>(this ReadOnlySpan<T> span, T value, int startIndex, delegate*<T, T, bool> comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | span | |
| T | value | |
| int | startIndex | |
| delegate*<T, T, bool> | comparer |
Returns
| Type | Description |
|---|---|
| int |
Type Parameters
| Name | Description |
|---|---|
| T |
IndexOf<T>(ReadOnlySpan<T>, T, int, Func<T, T, bool>)
Returns the zero-based index of the first occurrence of the specified value in the Span<T>. The search starts at a specified position.
Declaration
public static int IndexOf<T>(this ReadOnlySpan<T> span, T value, int startIndex, Func<T, T, bool> comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | span | |
| T | value | The value to search for. |
| int | startIndex | The search starting position. |
| Func<T, T, bool> | comparer | The comparer used to compare the expected value and the actual value from the span. |
Returns
| Type | Description |
|---|---|
| int | The zero-based index position of |
Type Parameters
| Name | Description |
|---|---|
| T |
Initialize<T>(Span<T>)
Initializes each element in the span.
Declaration
public static void Initialize<T>(this Span<T> span) where T : new()
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | span | The span of elements. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the element. |
Remarks
This method has the same behavior as Initialize() and supports reference types.
IsBitwiseAndNonZero<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
Determines whether the specified value and the given mask produces non-zero bitwise AND.
Declaration
public static bool IsBitwiseAndNonZero<T>(this ReadOnlySpan<T> x, ReadOnlySpan<T> mask) where T : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | x | |
| ReadOnlySpan<T> | mask | The mask. |
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T |
Move<T>(Span<T>, Range, Index)
Moves the range within the span to the specified index.
Declaration
public static void Move<T>(this Span<T> span, Range range, Index destinationIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | span | |
| Range | range | The range of elements within the source span to move. |
| Index | destinationIndex | The index of the element before which |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
Sort<T>(Span<T>, delegate*<T?, T?, int>)
Declaration
[CLSCompliant(false)]
public static void Sort<T>(this Span<T> span, delegate*<T?, T?, int> comparison)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | span | |
| delegate*<T, T, int> | comparison |
Type Parameters
| Name | Description |
|---|---|
| T |
Swap<T>(Span<T>, Range, Range)
Swaps two ranges within the same span.
Declaration
public static void Swap<T>(this Span<T> span, Range range1, Range range2)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | span | |
| Range | range1 | The first range. |
| Range | range2 | The second range. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| ArgumentException |
|
Swap<T>(Span<T>, Span<T>)
Swaps contents of the two spans.
Declaration
public static void Swap<T>(this Span<T> span, Span<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | span | |
| Span<T> | other | The second span. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | The length of |
TrimLength<T>(ReadOnlySpan<T>, int)
Trims the span to specified length if it exceeds it.
If length is less that maxLength then the original span returned.
Declaration
public static ReadOnlySpan<T> TrimLength<T>(this ReadOnlySpan<T> span, int maxLength)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | span | |
| int | maxLength | Maximum length. |
Returns
| Type | Description |
|---|---|
| ReadOnlySpan<T> | Trimmed span. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
TrimLength<T>(Span<T>, int)
Trims the span to specified length if it exceeds it.
If length is less that maxLength then the original span returned.
Declaration
public static Span<T> TrimLength<T>(this Span<T> span, int maxLength)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | span | |
| int | maxLength | Maximum length. |
Returns
| Type | Description |
|---|---|
| Span<T> | Trimmed span. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
TrimLength<T>(Span<T>, int, out Span<T>)
Trims the span to specified length if it exceeds it.
If length is less that maxLength then the original span returned.
Declaration
public static Span<T> TrimLength<T>(this Span<T> span, int maxLength, out Span<T> rest)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | span | |
| int | maxLength | Maximum length. |
| Span<T> | rest | The rest of |
Returns
| Type | Description |
|---|---|
| Span<T> | Trimmed span. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
op_BitwiseAnd<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)
Determines whether the specified value and the given mask produces non-zero bitwise AND.
Declaration
public static bool op_BitwiseAnd<T>(ReadOnlySpan<T> value, ReadOnlySpan<T> mask) where T : unmanaged
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | value | The value to check. |
| ReadOnlySpan<T> | mask | The mask. |
Returns
| Type | Description |
|---|---|
| bool |
Type Parameters
| Name | Description |
|---|---|
| T |
op_Modulus<T>(ReadOnlySpan<T>, int)
Trims the span to specified length if it exceeds it.
If length is less that maxLength then the original span returned.
Declaration
public static ReadOnlySpan<T> op_Modulus<T>(ReadOnlySpan<T> x, int maxLength)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | x | The span to trim. |
| int | maxLength | Maximum length. |
Returns
| Type | Description |
|---|---|
| ReadOnlySpan<T> | Trimmed span. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
op_Modulus<T>(Span<T>, int)
Trims the span to specified length if it exceeds it.
If length is less that maxLength then the original span returned.
Declaration
public static Span<T> op_Modulus<T>(Span<T> x, int maxLength)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | x | The span to trim. |
| int | maxLength | Maximum length. |
Returns
| Type | Description |
|---|---|
| Span<T> | Trimmed span. |
Type Parameters
| Name | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
op_UnsignedRightShift<T>(ReadOnlySpan<T>, Span<T>)
Copies the contents from the source span into a destination span.
Declaration
public static int op_UnsignedRightShift<T>(ReadOnlySpan<T> source, Span<T> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<T> | source | Source memory. |
| Span<T> | destination | Destination memory. |
Returns
| Type | Description |
|---|---|
| int | The number of copied elements. |
Type Parameters
| Name | Description |
|---|---|
| T |