System.Generics.Collections.TArray.BinarySearch

提供: RAD Studio API Documentation
移動先: 案内検索

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 */;

プロパティ

種類 可視性 ソース ユニット
function public
System.Generics.Collections.pas
System.Generics.Collections.hpp
System.Generics.Collections TArray

説明

二分探索を用い、ソートされたジェネリック配列を検索して要素を見つけます。

BinarySearch メソッドは、二分探索を用い、配列 Values を検索して要素 Item を見つけます。

BinarySearch は、要素が見つかった場合 True を返し、そうでない場合 False を返します。要素が見つかった場合、Item の 0 から始まるインデックスが FoundIndex に格納されます。見つからなかった場合、Item より大きい最初の要素のインデックスが FoundIndex に格納されます。

Item と等しい要素が配列内に複数ある場合、最初に一致した要素のインデックスが FoundIndex に格納されて返されます。これは、一致したいずれかの要素のインデックスであり、最初の要素のインデックスとは限りません。

BinarySearch は、n 個の要素を持つ配列に対して O(log n) の計算量の探索アルゴリズムを用いて実装されます。

メモ:  BinarySearch では、配列がソートされている必要があります。

メモ:  Comparer パラメータが指定されている場合、要素の比較に使用されます。指定されていない場合は、配列要素のデフォルトの比較クラスが使用されます。

関連項目