You are here: Symbol Reference > MtxExprInt Namespace > Classes > VectorInt Record > public > BinarySearch Method > VectorInt.BinarySearch Method (Integer, integer)
MtxVec VCL
ContentsIndex
PreviousUpNext
VectorInt.BinarySearch Method (Integer, integer)

Finds exact or closest index match for X in object values using binary search.

Pascal
function BinarySearch(const X: Integer; var XIndex: integer): boolean; overload;

True, if found and the index of the next bigger or smaller value in XIndex, if not found.

The data in the vector must be sorted in ascending order for this function to work correctly. The closest match is the index of first bigger or smaller value in the array. 

To ensure bigger value write: 

 

Data := [0,2,3]; Data.BinarySearch(Value, XIndex); if Data[XIndex] > Value then Dec(XIndex);

 

To ensure smaller value write: 

 

Data := [0,2,3]; Data.BinarySearch(1, XIndex); if Data[XIndex] < Value then Inc(XIndex);
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!