Table of Contents

Method BinarySearch

Namespace
Zyl.ExSpans
Assembly
ExSpans.dll

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

span ExSpan<T>

The sorted ExSpan<T> to search.

comparable IComparable<T>

The IComparable<T> to use when comparing.

Returns

nint

The zero-based index of comparable in the sorted span, if comparable is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than comparable or, if there is no larger element, the bitwise complement of Length.

Type Parameters

T

The element type of the span.

Exceptions

ArgumentNullException

comparable is 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

span ExSpan<T>

The sorted ExSpan<T> to search.

comparable TComparable

The TComparable to use when comparing.

Returns

nint

The zero-based index of comparable in the sorted span, if comparable is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than comparable or, if there is no larger element, the bitwise complement of Length.

Type Parameters

T

The element type of the span.

TComparable

The specific type of IComparable<T>.

Exceptions

ArgumentNullException

comparable is 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

span ExSpan<T>

The sorted ExSpan<T> to search.

value T

The object to locate. The value can be null for reference types.

comparer TComparer

The TComparer to use when comparing.

Returns

nint

The zero-based index of value in the sorted span, if value is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than value or, if there is no larger element, the bitwise complement of Length.

Type Parameters

T

The element type of the span.

TComparer

The specific type of IComparer<T>.

Exceptions

ArgumentNullException

comparer is 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

span ReadOnlyExSpan<T>

The sorted ReadOnlyExSpan<T> to search.

comparable IComparable<T>

The IComparable<T> to use when comparing.

Returns

nint

The zero-based index of comparable in the sorted span, if comparable is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than comparable or, if there is no larger element, the bitwise complement of Length.

Type Parameters

T

The element type of the span.

Exceptions

ArgumentNullException

comparable is 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

span ReadOnlyExSpan<T>

The sorted ReadOnlyExSpan<T> to search.

comparable TComparable

The TComparable to use when comparing.

Returns

nint

The zero-based index of comparable in the sorted span, if comparable is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than comparable or, if there is no larger element, the bitwise complement of Length.

Type Parameters

T

The element type of the span.

TComparable

The specific type of IComparable<T>.

Exceptions

ArgumentNullException

comparable is 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

span ReadOnlyExSpan<T>

The sorted ReadOnlyExSpan<T> to search.

value T

The object to locate. The value can be null for reference types.

comparer TComparer

The TComparer to use when comparing.

Returns

nint

The zero-based index of value in the sorted span, if value is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than value or, if there is no larger element, the bitwise complement of Length.

Type Parameters

T

The element type of the span.

TComparer

The specific type of IComparer<T>.

Exceptions

ArgumentNullException

comparer is null .