BSEARCH(3C) COMMAND REFERENCE BSEARCH(3C)
NAME
bsearch - binary search
SYNOPSIS
char *bsearch ((char *) key, (char *) base, nel, sizeof
(*key), compar)
unsigned nel;
int (*compar)( );
DESCRIPTION
Bsearch is a binary search routine generalized from Knuth
(6.2.1) Algorithm B. It returns a pointer into a table
indicating where a datum may be found. The table must be
previously sorted in increasing order according to a
provided comparison function.
Key points to the datum to be sought in the table.
Base points to the element at the base of the table.
Nel is the number of elements in the table.
Compar is the name of the comparison function, which is
called with two arguments that point to the elements being
compared. The function must return an integer less than,
equal to, or greater than zero according as the first
argument is to be considered less than, equal to, or greater
than the second.
DIAGNOSTICS
A NULL pointer is returned if the key cannot be found in the
table.
CAVEATS
The pointers to the key and the element at the base of the
table should be of type pointer-to-element, and cast to type
pointer-to-character.
The comparison function need not compare every byte, so
arbitrary data may be contained in the elements in addition
to the values being compared.
Although declared as type pointer-to-character, the value
returned should be cast into type pointer-to-element.
SEE ALSO
lsearch(3c), hsearch(3c), qsort(3c), tsearch(3c).
Printed 10/17/86 1
%%index%%
na:72,59;
sy:131,704;
de:835,935;
di:1770,165;
ca:1935,493;
se:2428,179;
%%index%%000000000106