System.Generics.Collections.TList.BinarySearch

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

Delphi

function BinarySearch(const Item: T; out Index: Integer): Boolean; overload;
function BinarySearch(const Item: T; out Index: Integer; const AComparer: IComparer<T>): Boolean; overload;

C++

bool __fastcall BinarySearch(const T Item, /* out */ int &Index)/* overload */;
bool __fastcall BinarySearch(const T Item, /* out */ int &Index, const System::DelphiInterface<System::Generics::Defaults::IComparer__1<T> > AComparer)/* 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) 操作になります。

関連項目