Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

NativeSortExtension.BinarySearch

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static int BinarySearch(T* ptr, int length, T value);

Parameters

Parameter Description
ptr The array to search.
value The value to locate.
length The number of elements to search. Indexes greater than or equal to length won't be searched.

Returns

int The zero-based index of the value to find in the sorted array. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in a sorted array by binary search.

If the array is not sorted, the value might not be found, even if it's present in the array.


Declaration

public static int BinarySearch(T* ptr, int length, T value, U comp);

Parameters

Parameter Description
ptr The array to search.
value The value to locate.
length The number of elements to search. Indexes greater than or equal to length won't be searched.
comp The comparison function used to determine the relative order of the elements.

Returns

int The zero-based index of the value to find in the sorted array. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in a sorted array by binary search using a custom comparison.

If the array is not sorted, the value might not be found, even if it's present in the array.


Declaration

public static int BinarySearch(NativeArray<T> container, T value);

Parameters

Parameter Description
container The array to search.
value The value to locate.

Returns

int The zero-based index of the value to find in the sorted array. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in this sorted array by binary search.

If the array is not sorted, the value might not be found, even if it's present in this array.


Declaration

public static int BinarySearch(NativeArray<T> container, T value, U comp);

Parameters

Parameter Description
container The array to search.
value The value to locate.
comp The comparison function used to determine the relative order of the elements.

Returns

int The zero-based index of the value to find in the sorted array. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in this sorted array by binary search using a custom comparison.

If the array is not sorted, the value might not be found, even if it's present in this array.


Declaration

public static int BinarySearch(NativeList<T> container, T value);

Parameters

Parameter Description
container The list to search.
value The value to locate.

Returns

int The zero-based index of the value to find in the sorted list. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in this sorted list by binary search.

If this list is not sorted, the value might not be found, even if it's present in this list.


Declaration

public static int BinarySearch(NativeList<T> container, T value, U comp);

Parameters

Parameter Description
container The list to search.
value The value to locate.
comp The comparison function used to determine the relative order of the elements.

Returns

int The zero-based index of the value to find in the sorted list. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in this sorted list by binary search using a custom comparison.

If this list is not sorted, the value may not be found, even if it's present in this list.


Declaration

public static int BinarySearch(UnsafeList<T> container, T value);

Parameters

Parameter Description
container The list to search.
value The value to locate.

Returns

int The zero-based index of the value to find in the sorted list. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in this sorted list by binary search.

If this list is not sorted, the value might not be found, even if it's present in this list.


Declaration

public static int BinarySearch(UnsafeList<T> container, T value, U comp);

Parameters

Parameter Description
container The list to search.
value The value to locate.
comp The comparison function used to determine the relative order of the elements.

Returns

int The zero-based index of the value to find in the sorted list. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in this sorted list by binary search using a custom comparison.

If this list is not sorted, the value might not be found, even if it's present in this list.


Declaration

public static int BinarySearch(ReadOnlySpan<T> roSpan, T value);

Parameters

Parameter Description
roSpan The ReadOnlySpan to search.
value The value to locate.

Returns

int The zero-based index of the value to find in the sorted ReadOnlySpan. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in this sorted ReadOnlySpan by binary search.

If this ReadOnlySpan is not sorted, the value might not be found, even if it's present in this ReadOnlySpan.


Declaration

public static int BinarySearch(ReadOnlySpan<T> roSpan, T value, U comp);

Parameters

Parameter Description
roSpan The ReadOnlySpan to search.
value The value to locate.
comp The comparison function used to determine the relative order of the elements.

Returns

int The zero-based index of the value to find in the sorted ReadOnlySpan. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in this sorted ReadOnlySpan by binary search using a custom comparison.

If this ReadOnlySpan is not sorted, the value might not be found, even if it's present in this ReadOnlySpan.


Declaration

public static int BinarySearch(NativeSlice<T> container, T value);

Parameters

Parameter Description
container The slice to search.
value The value to locate.

Returns

int The zero-based index of the value to find in the sorted slice. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in this sorted slice by binary search.

If this slice is not sorted, the value might not be found, even if it's present in this slice.


Declaration

public static int BinarySearch(NativeSlice<T> container, T value, U comp);

Parameters

Parameter Description
container The slice to search.
value The value to locate.
comp The comparison function used to determine the relative order of the elements.

Returns

int The zero-based index of the value to find in the sorted slice. If it is not found, a negative number that is the bitwise complement of the index of the next element larger than item or, if there is no larger element, the bitwise complement of the length.

Description

Finds a value in this sorted slice by binary search using a custom comparison.

If this slice is not sorted, the value might not be found, even if it's present in this slice.