Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ bsearch(3C) — UTek 4.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

lsearch(3c)

hsearch(3c)

qsort(3c)

tsearch(3c)



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), and tsearch(3c).







Printed 3/13/89                                                 1





































































%%index%%
na:336,75;
sy:411,1084;
de:1495,1112;
di:2607,209;
ca:2816,521;
se:3337,210;
%%index%%000000000110

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026