System.Generics.Collections.TList.BinarySearch
Delphi
function BinarySearch(const Item: T; out FoundIndex: NativeInt): Boolean; overload;
function BinarySearch(const Item: T; out FoundIndex: NativeInt; const AComparer: IComparer<T>): Boolean; overload;
function BinarySearch(const Item: T; out FoundIndex: NativeInt; const AComparer: IComparer<T>; Index, Count: NativeInt): Boolean; overload;
C++
bool __fastcall BinarySearch(const T Item, /* out */ System::NativeInt &FoundIndex)/* overload */;
bool __fastcall BinarySearch(const T Item, /* out */ System::NativeInt &FoundIndex, const System::DelphiInterface<System::Generics::Defaults::IComparer__1<T> > AComparer)/* overload */;
bool __fastcall BinarySearch(const T Item, /* out */ System::NativeInt &FoundIndex, const System::DelphiInterface<System::Generics::Defaults::IComparer__1<T> > AComparer, System::NativeInt Index, System::NativeInt Count)/* overload */;
プロパティ
種類 | 可視性 | ソース | ユニット | 親 |
---|---|---|---|---|
function | public | System.Generics.Collections.pas System.Generics.Collections.hpp |
System.Generics.Collections | TList |
説明
バイナリ検索を使用して、要素のソートされたリストを検索します。
オーバーロードされたメソッド BinarySearch は、バイナリ検索を使用して、リスト内の要素(Item)を検索します。要素が見つかった場合、このメソッドは true を返します。それ以外の場合は、false を返します。要素が見つかった場合、Item の 0 から始まるインデックスが Index に格納されます。要素が見つからなかった場合、Item よりも大きい最初のエントリのインデックスが Index に格納されます。
メモ: BinarySearch では、リストがソートされている必要があります。IndexOf メソッドでは、リストがソートされている必要はありませんが、通常、BinarySearch より低速です。
リスト内に Item と等しい要素が複数ある場合、最初に一致した要素のインデックスが Index に返されます。これは、一致した項目のいずれかのインデックスであり、最初の項目とは限りません。
比較関数 AComparer が、要素を比較するために提供される場合があります。
Index がリストの範囲外にある場合、EArgumentOutOfRangeException 例外が発生します。
これは、n エントリを持つリストに対する O(log n) 操作になります。