These subroutines perform a binary search for the locations of the elements
of sequence x in another sequence y, where y
has been sorted into ascending order. The first occurrence of each
element is found. When an exact match is not found, the position of the
next larger element in y is indicated. The locations are
returned in the indices array INDX, and, optionally, return codes
indicating whether the exact elements were found are returned in array
RC.
x, y | Subroutine |
Integer | IBSRCH |
Short-precision real | SBSRCH |
Long-precision real | DBSRCH |
Fortran | CALL IBSRCH | SBSRCH | DBSRCH (x, incx, n, y, incy, m, indx, rc, iopt) |
C and C++ | ibsrch | sbsrch | dbsrch (x, incx, n, y, incy, m, indx, rc, iopt); |
PL/I | CALL IBSRCH | SBSRCH | DBSRCH (x, incx, n, y, incy, m, indx, rc, iopt); |
Specified as: a one-dimensional array of (at least) length 1+(m-1)|incy|, containing numbers of the data type indicated in Table 152.
If iopt = 0, the rc argument is not used in the computation.
If iopt = 1, the rc argument is used in the computation.
Specified as: a fullword integer; iopt = 0 or 1.
Returned as: a one-dimensional array of length n, containing fullword integers; 1 <= (INDX elements) <= m+1.
If iopt = 0, then rc is not used, and its contents remain unchanged.
If iopt = 1, it is the array, referred to as RC, containing the n return codes that indicate whether the elements in sequence x were found in sequence y. For i = 1, n, elements RC(i) = 0 if xi matches an element in sequence y, and RC(i) = 1 if an exact match is not found in sequence y.
Returned as: a one-dimensional array of length n, containing fullword integers; RC(i) = 0 or 1.
These subroutines perform a binary search for the first occurrence (or last occurrence, using negative stride) of the locations of the elements of sequence x in another sequence y, where y must be sorted into ascending order before calling this subroutine. The first occurrence of each element is found. Two arrays are returned, containing the results of the binary searches:
The results returned for the INDX and RC arrays are expressed as follows:
where:
See reference [75]. If n is 0, no search is performed. If m is 0, then:
It is important to note that a negative stride for sequence y reverses the direction of the search, because the order of the sequence elements is reversed in the array. For more details on sorting sequences, see Function.
None
This example shows a search where sequences x and y have positive strides, and where the optional return codes are returned as part of the output.
X INCX N Y INCY M INDX RC IOPT | | | | | | | | | CALL IBSRCH( X , 2 , 5 , Y , 1 , 10 , INDX , RC , 1 ) X = (-3, . , 125, . , 30, . , 20, . , 70) Y = (10, 20, 30, 30, 40, 50, 60, 80, 90, 100)
INDX = (1, 11, 3, 2, 8) RC = (1, 1, 0, 0, 1)
This example shows the same calling sequence as in Example 1, except that it includes the IOPT argument, specified as 1. This is equivalent to using the calling sequence in Example 1 and gives the same results.
X INCX N Y INCY M INDX RC IOPT | | | | | | | | | CALL IBSRCH( X , 2 , 5 , Y , 1 , 10 , INDX , RC , 1 )
This example shows a search where sequence x has a negative stride, and sequence y has a positive stride. The optional return codes are not requested, because IOPT is specified as 0.
X INCX N Y INCY M INDX RC IOPT | | | | | | | | | CALL IBSRCH( X , -2 , 5 , Y , 1 , 10 , INDX , RC , 0 ) X = (-3, . , 125, . , 30, . , 20, . , 70) Y = (10, 20, 30, 30, 40, 50, 60, 80, 90, 100)
INDX = (8, 2, 3, 11, 1) RC =(not relevant)
This example shows a search where sequence x has a positive stride, and sequence y has a negative stride. As shown below, elements of y are in descending order in array Y. The optional return codes are not requested, because IOPT is specified as 0.
X INCX N Y INCY M INDX RC IOPT | | | | | | | | | CALL IBSRCH( X , 2 , 5 , Y , -1 , 10 , INDX , RC , 0 )
INDX = (1, 11, 3, 2, 8)