Method BinarySearch
BinarySearch<T>(T*, int, T)
Finds a value in a sorted array by binary search.
Declaration
public static int BinarySearch<T>(T* ptr, int length, T value) where T : unmanaged, IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
T* | ptr | The array to search. |
int | length | The number of elements to search. Indexes greater than or equal to |
T | value | The value to locate. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
Remarks
If the array is not sorted, the value might not be found, even if it's present in the array.
BinarySearch<T, U>(T*, int, T, U)
Finds a value in a sorted array by binary search using a custom comparison.
Declaration
public static int BinarySearch<T, U>(T* ptr, int length, T value, U comp) where T : unmanaged where U : IComparer<T>
Parameters
Type | Name | Description |
---|---|---|
T* | ptr | The array to search. |
int | length | The number of elements to search. Indexes greater than or equal to |
T | value | The value to locate. |
U | comp | The comparison function used to determine the relative order of the elements. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
U | The type of the comparer. |
Remarks
If the array is not sorted, the value might not be found, even if it's present in the array.
BinarySearch<T>(NativeArray<T>, T)
Finds a value in this sorted array by binary search.
Declaration
public static int BinarySearch<T>(this NativeArray<T> array, T value) where T : unmanaged, IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | array | The array to search. |
T | value | The value to locate. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
Remarks
If the array is not sorted, the value might not be found, even if it's present in this array.
BinarySearch<T, U>(NativeArray<T>, T, U)
Finds a value in this sorted array by binary search using a custom comparison.
Declaration
public static int BinarySearch<T, U>(this NativeArray<T> array, T value, U comp) where T : unmanaged where U : IComparer<T>
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | array | The array to search. |
T | value | The value to locate. |
U | comp | The comparison function used to determine the relative order of the elements. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
U | The comparer type. |
Remarks
If the array is not sorted, the value might not be found, even if it's present in this array.
BinarySearch<T>(ReadOnly, T)
Finds a value in this sorted array by binary search.
Declaration
public static int BinarySearch<T>(this NativeArray<T>.ReadOnly array, T value) where T : unmanaged, IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T>.ReadOnly | array | The array to search. |
T | value | The value to locate. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
Remarks
If the array is not sorted, the value might not be found, even if it's present in this array.
BinarySearch<T, U>(ReadOnly, T, U)
Finds a value in this sorted array by binary search using a custom comparison.
Declaration
public static int BinarySearch<T, U>(this NativeArray<T>.ReadOnly array, T value, U comp) where T : unmanaged where U : IComparer<T>
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T>.ReadOnly | array | The array to search. |
T | value | The value to locate. |
U | comp | The comparison function used to determine the relative order of the elements. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
U | The comparer type. |
Remarks
If the array is not sorted, the value might not be found, even if it's present in this array.
BinarySearch<T>(NativeList<T>, T)
Finds a value in this sorted list by binary search.
Declaration
public static int BinarySearch<T>(this NativeList<T> list, T value) where T : unmanaged, IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
NativeList<T> | list | The list to search. |
T | value | The value to locate. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
Remarks
If this list is not sorted, the value might not be found, even if it's present in this list.
BinarySearch<T, U>(NativeList<T>, T, U)
Finds a value in this sorted list by binary search using a custom comparison.
Declaration
public static int BinarySearch<T, U>(this NativeList<T> list, T value, U comp) where T : unmanaged where U : IComparer<T>
Parameters
Type | Name | Description |
---|---|---|
NativeList<T> | list | The list to search. |
T | value | The value to locate. |
U | comp | The comparison function used to determine the relative order of the elements. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
U | The type of the comparer. |
Remarks
If this list is not sorted, the value may not be found, even if it's present in this list.
BinarySearch<T>(UnsafeList<T>, T)
Finds a value in this sorted list by binary search.
Declaration
public static int BinarySearch<T>(this UnsafeList<T> list, T value) where T : unmanaged, IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
UnsafeList<T> | list | The list to search. |
T | value | The value to locate. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
Remarks
If this list is not sorted, the value might not be found, even if it's present in this list.
BinarySearch<T, U>(UnsafeList<T>, T, U)
Finds a value in this sorted list by binary search using a custom comparison.
Declaration
public static int BinarySearch<T, U>(this UnsafeList<T> list, T value, U comp) where T : unmanaged where U : IComparer<T>
Parameters
Type | Name | Description |
---|---|---|
UnsafeList<T> | list | The list to search. |
T | value | The value to locate. |
U | comp | The comparison function used to determine the relative order of the elements. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
U | The type of the comparer. |
Remarks
If this list is not sorted, the value might not be found, even if it's present in this list.
BinarySearch<T>(NativeSlice<T>, T)
Finds a value in this sorted slice by binary search.
Declaration
public static int BinarySearch<T>(this NativeSlice<T> slice, T value) where T : unmanaged, IComparable<T>
Parameters
Type | Name | Description |
---|---|---|
NativeSlice<T> | slice | The slice to search. |
T | value | The value to locate. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
Remarks
If this slice is not sorted, the value might not be found, even if it's present in this slice.
BinarySearch<T, U>(NativeSlice<T>, T, U)
Finds a value in this sorted slice by binary search using a custom comparison.
Declaration
public static int BinarySearch<T, U>(this NativeSlice<T> slice, T value, U comp) where T : unmanaged where U : IComparer<T>
Parameters
Type | Name | Description |
---|---|---|
NativeSlice<T> | slice | The slice to search. |
T | value | The value to locate. |
U | comp | The comparison function used to determine the relative order of the elements. |
Returns
Type | Description |
---|---|
int | If found, the index of the located value. If not found, the return value is negative. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements. |
U | The type of the comparer. |
Remarks
If this slice is not sorted, the value might not be found, even if it's present in this slice.