BSEARCHQQ

Run-Time Function: Performs a binary search of a sorted one-dimensional array for a specified element. The array elements cannot be derived types or structures.

Module: USE DFLIB

Syntax

result = BSEARCHQQ (adrkey, adrarray, length, size)

adrkey
(Input) Address of the variable containing the element to be found (returned by LOC). INTEGER(4) on ia32 processors; INTEGER(8) on ia64 processors.


adrarray
(Input) Address of the array (returned by LOC). INTEGER(4) on ia32 processors; INTEGER(8) on ia64 processors.


length
(Input) INTEGER(4). Number of elements in the array.


size
(Input) INTEGER(4). Positive constant less than 32,767 that specifies the kind of array to be sorted. The following constants, defined in DFLIB.F90 in the \DF98\INCLUDE subdirectory, specify type and kind for numeric arrays:


Constant Type of array
SRT$INTEGER1 INTEGER(1)
SRT$INTEGER2 INTEGER(2) or equivalent
SRT$INTEGER4 INTEGER(4) or equivalent
SRT$REAL4 REAL(4) or equivalent
SRT$REAL8 REAL(8) or equivalent

If the value provided in size is not a symbolic constant and is less than 32,767, the array is assumed to be a character array with size characters per element.

Results:

INTEGER(4). Array index of the matched entry, or 0 if the entry is not found.

The array must be sorted in ascending order before being searched.


Caution: The location of the array and the element to be found must both be passed by address using the LOC function. This defeats Fortran type checking, so you must make certain that the length and size arguments are correct, and that size is the same for the element to be found and the array searched.

If you pass invalid arguments, BSEARCHQQ attempts to search random parts of memory. If the memory it attempts to search is allocated to the current process, that memory is searched. If the memory it attempts to search is not allocated to the current process, the operating system intervenes, the program is halted, and you receive a General Protection Violation message.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: SORTQQ, LOC

Example

USE DFLIB
INTEGER(4) array(10), length
INTEGER(4) result, target
length = SIZE(array)
...
result = BSEARCHQQ(LOC(target),LOC(array),length,SRT$INTEGER4)