Click or drag to resize

AScanBinExact Function

X#
Scan a sorted array until there is an exact match or a code block returns 0.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax
 FUNCTION AScanBinExact(
	aTarget AS ARRAY,
	uSearch AS USUAL
) AS DWORD
Request Example View Source

Parameters

aTarget
Type: Array
The sorted array to scan.
uSearch
Type: Usual
The value to scan for.
Unless this argument is a code block, it must match the data type of the elements in aTarget.
If uSearch is a code block, it should return a numeric value that indicates the outcome of the comparison: a positive value indicates that uSearch is greater than the current array element, a 0 stands for equality, and a negative value indicates that uSearch is less than the current array element.

Return Value

Type: DWord
If uSearch is a code block, AScanBinExact() returns the position of the element if the code block returned 0.
Otherwise, AScanBinExact() returns the position of an exact-matching element.
If multiple occurrences of the same element exist, the returned exact match is not necessarily the lowest numbered element since AScanBinExact() uses a binary search algorithm.
AScanBinExact() returns 0 if no exact match is found.
Remarks
AScanBinExact() is the same as AScanBin() except that == is used for matching instead of =.
Examples
This example shows the difference between AScanBinExact() and AScanBin():
X#
1aArray := {"Larger", "Largest"}    // Already sorted
2? "Larger" = "Large"            // TRUE
3? "Larger" == "Large"            // FALSE
4? AScanBin(aArray, "Large")        // 1
5? AScanBinExact(aArray, "Large")    // 0
See Also