AT&T UNIX™PC Unix System V Users Manual - tenox

AT&T UNIX™PC Unix System V Users Manual - tenox AT&T UNIX™PC Unix System V Users Manual - tenox

01.01.2013 Views

·�

BSEARCH ( 3C ) BSEARCH ( 3C ) NAME bsearch - binary search SYNOPSIS char * bsearch ( (char *) key, (char *) base, nel, sizeof (*key), compar) unsigned nel; int (*compar)( ); DESCRWTION 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. Net 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. NOTES 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-tocharacter. 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). - 1 -

BSEARCH ( 3C ) BSEARCH ( 3C )<br />

NAME<br />

bsearch - binary search<br />

SYNOPSIS<br />

char * bsearch ( (char *) key, (char *) base, nel, sizeof<br />

(*key), compar)<br />

unsigned nel;<br />

int (*compar)( );<br />

DESCRWTION<br />

Bsearch is a binary search routine generalized from Knuth (6.2.1)<br />

Algorithm B. It returns a pointer into a table indicating where a<br />

datum may be found. The table must be previously sorted in<br />

increasing order according to a provided comparison function.<br />

Key points to the datum to be sought in the table. Base points<br />

to the element at the base of the table. Net is the number of elements<br />

in the table. Compar is the name of the comparison function,<br />

which is called with two arguments that point to the elements<br />

being compared. The function must return an integer less<br />

than, equal to, or greater than zero according as the first argument<br />

is to be considered less than, equal to, or greater than the<br />

second.<br />

DIAGNOSTICS<br />

A NULL pointer IS returned if the key cannot be found in the<br />

table.<br />

NOTES<br />

The pointers to the key and the element at the base of the table<br />

should be of type pointer-to-element, and cast to type pointer-tocharacter.<br />

The comparison function need not compare every byte, so arbitrary<br />

data may be contained in the elements in addition to the<br />

values being compared.<br />

Although declared as type pointer-to-character, the value returned<br />

should be cast into type pointer-to-element.<br />

SEE ALSO<br />

lsearch(3C), hsearch(3C), qsort(3C), tsearch(3C).<br />

- 1 -

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!