System.Generics.Collections.TArray.BinarySearch

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

class function BinarySearch<T>(const Values: array of T; const Item: T;  out FoundIndex: Integer; const Comparer: IComparer<T>; Index, Count: Integer): Boolean; overload; static;
class function BinarySearch<T>(const Values: array of T; const Item: T;  out FoundIndex: Integer; const Comparer: IComparer<T>): Boolean; overload; static;
class function BinarySearch<T>(const Values: array of T; const Item: T;  out FoundIndex: Integer): Boolean; overload; static; static;

C++

template<typename T> static bool __fastcall BinarySearch(const T *Values, const int Values_High, const T Item, /* out */ int &FoundIndex, const System::DelphiInterface<System::Generics::Defaults::IComparer__1<T> > Comparer, int Index, int Count)/* overload */;
template<typename T> static bool __fastcall BinarySearch(const T *Values, const int Values_High, const T Item, /* out */ int &FoundIndex, const System::DelphiInterface<System::Generics::Defaults::IComparer__1<T> > Comparer)/* overload */;
template<typename T> static bool __fastcall BinarySearch(const T *Values, const int Values_High, const T Item, /* out */ int &FoundIndex)/* overload */;

Properties

Type Visibility Source Unit Parent
function public
System.Generics.Collections.pas
System.Generics.Collections.hpp
System.Generics.Collections TArray

Description

Search generic sorted array for an element, using binary search.

The BinarySearch method searches the Values array for the Item element, using binary search.

BinarySearch returns True if it finds the element and False otherwise. If found, FoundIndex contains the zero-based index of Item. If not found, FoundIndex contains the index of the first entry larger than Item.

If there is more than one element in the array equal to Item, the index of the first match is returned in FoundIndex. This is the index of any of the matching items, not necessarily of the first item.

BinarySearch is implemented using an O(log n) search algorithm, for an array with n entries.

Note: BinarySearch requires that the array be sorted.

Note: If the Comparer parameter is provided, it is used to compare elements; otherwise the default comparator for the array elements is used.

See Also

Code Examples