System.Generics.Collections.TArray.BinarySearch

De RAD Studio API Documentation
Aller à : navigation, rechercher

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;

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

Propriétés

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

Description

Recherche un élément dans un tableau générique trié, au moyen d'une recherche binaire.

La méthode BinarySearch recherche dans le tableau Values l'élément Item, au moyen d'une recherche binaire.

La méthode BinarySearch renvoie True si elle trouve l'élément et False sinon. En cas de recherche fructueuse, FoundIndex contient l'index de base zéro de l'élément Item. En cas de recherche infructueuse, FoundIndex contient l'index de la première entrée supérieure à Item.

Si plusieurs éléments du tableau correspondent à Item, l'index de la première occurrence est renvoyé dans FoundIndex. Il s'agit de l'index d'un des éléments correspondants, pas nécessairement celui du premier élément.

BinarySearch est implémentée en utilisant un algorithme de recherche O(log n), pour un tableau à n entrées.

Remarque :  BinarySearch nécessite que le tableau soit trié.

Remarque :  Si le paramètre Comparer est fourni, il est utilisé pour comparer les éléments. Sinon, le comparateur par défaut des éléments de tableau est utilisé.

Voir aussi