Method BinarySearch
BinarySearch<T>(ExSpan<T>, IComparable<T>)
Searches an entire sorted ExSpan<T> for a value using the specified IComparable<T> generic interface.
public static nint BinarySearch<T>(this ExSpan<T> span, IComparable<T> comparable)
Parameters
spanExSpan<T>The sorted ExSpan<T> to search.
comparableIComparable<T>The IComparable<T> to use when comparing.
Returns
- nint
The zero-based index of
comparablein the sortedspan, ifcomparableis found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger thancomparableor, if there is no larger element, the bitwise complement of Length.
Type Parameters
TThe element type of the span.
Exceptions
- ArgumentNullException
comparableis null .
BinarySearch<T, TComparable>(ExSpan<T>, TComparable)
Searches an entire sorted ExSpan<T> for a value
using the specified TComparable generic type.
public static nint BinarySearch<T, TComparable>(this ExSpan<T> span, TComparable comparable) where TComparable : IComparable<T>
Parameters
spanExSpan<T>The sorted ExSpan<T> to search.
comparableTComparableThe
TComparableto use when comparing.
Returns
- nint
The zero-based index of
comparablein the sortedspan, ifcomparableis found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger thancomparableor, if there is no larger element, the bitwise complement of Length.
Type Parameters
TThe element type of the span.
TComparableThe specific type of IComparable<T>.
Exceptions
- ArgumentNullException
comparableis null .
BinarySearch<T, TComparer>(ExSpan<T>, T, TComparer)
Searches an entire sorted ExSpan<T> for the specified value
using the specified TComparer generic type.
public static nint BinarySearch<T, TComparer>(this ExSpan<T> span, T value, TComparer comparer) where TComparer : IComparer<T>
Parameters
spanExSpan<T>The sorted ExSpan<T> to search.
valueTThe object to locate. The value can be null for reference types.
comparerTComparerThe
TComparerto use when comparing.
Returns
- nint
The zero-based index of
valuein the sortedspan, ifvalueis found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger thanvalueor, if there is no larger element, the bitwise complement of Length.
Type Parameters
TThe element type of the span.
TComparerThe specific type of IComparer<T>.
Exceptions
- ArgumentNullException
compareris null .
BinarySearch<T>(ReadOnlyExSpan<T>, IComparable<T>)
Searches an entire sorted ReadOnlyExSpan<T> for a value using the specified IComparable<T> generic interface.
public static nint BinarySearch<T>(this ReadOnlyExSpan<T> span, IComparable<T> comparable)
Parameters
spanReadOnlyExSpan<T>The sorted ReadOnlyExSpan<T> to search.
comparableIComparable<T>The IComparable<T> to use when comparing.
Returns
- nint
The zero-based index of
comparablein the sortedspan, ifcomparableis found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger thancomparableor, if there is no larger element, the bitwise complement of Length.
Type Parameters
TThe element type of the span.
Exceptions
- ArgumentNullException
comparableis null .
BinarySearch<T, TComparable>(ReadOnlyExSpan<T>, TComparable)
Searches an entire sorted ReadOnlyExSpan<T> for a value
using the specified TComparable generic type.
public static nint BinarySearch<T, TComparable>(this ReadOnlyExSpan<T> span, TComparable comparable) where TComparable : IComparable<T>
Parameters
spanReadOnlyExSpan<T>The sorted ReadOnlyExSpan<T> to search.
comparableTComparableThe
TComparableto use when comparing.
Returns
- nint
The zero-based index of
comparablein the sortedspan, ifcomparableis found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger thancomparableor, if there is no larger element, the bitwise complement of Length.
Type Parameters
TThe element type of the span.
TComparableThe specific type of IComparable<T>.
Exceptions
- ArgumentNullException
comparableis null .
BinarySearch<T, TComparer>(ReadOnlyExSpan<T>, T, TComparer)
Searches an entire sorted ReadOnlyExSpan<T> for the specified value
using the specified TComparer generic type.
public static nint BinarySearch<T, TComparer>(this ReadOnlyExSpan<T> span, T value, TComparer comparer) where TComparer : IComparer<T>
Parameters
spanReadOnlyExSpan<T>The sorted ReadOnlyExSpan<T> to search.
valueTThe object to locate. The value can be null for reference types.
comparerTComparerThe
TComparerto use when comparing.
Returns
- nint
The zero-based index of
valuein the sortedspan, ifvalueis found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger thanvalueor, if there is no larger element, the bitwise complement of Length.
Type Parameters
TThe element type of the span.
TComparerThe specific type of IComparer<T>.
Exceptions
- ArgumentNullException
compareris null .