Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ bsearch(3) — Digital UNIX 3.2c

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

hsearch(3)

lsearch(3)

qsort(3)

tsearch(3)

bsearch(3)  —  Subroutines

NAME

bsearch − Performs a binary search

LIBRARY

Standard C Library (libc.a)

SYNOPSIS

#include <stdlib.h>

void ∗bsearch(
    const void ∗key,
    const void ∗base,
    size_t nmemb,
    size_t size,
    int (∗compar)(const void ∗, const void ∗));

PARAMETERS

keyTarget of search. 

basePoints to the initial object in the array. 

nmembSpecifies the number of elements in the array. 

sizeSpecifies the byte size of each element of the array. 

comparPoints to the comparison function, which is called with two parameters that point to the key object and to an array member, in that order. 

DESCRIPTION

The bsearch() function does a binary search and returns a pointer in an array that indicates where an object is found. The array must have been previously sorted in increasing order according to a provided comparison function, compar. 

The compar comparison function is called with two parameters that point to objects that are compared during the search. This function returns an integer less than, equal to, or greater than 0 (zero) depending whether the object pointed to by the first const void ∗ parameter is to be considered less than, equal to, or greater than the second const void ∗ parameter. 

NOTES

The bsearch() function is reentrant, but care should be taken to ensure that the function supplied as argument compar is also reentrant. 

AES Support Level:
Full use.

RETURN VALUES

Upon successful completion, the bsearch() function returns a pointer to a matching object in the array.  A NULL is returned when no match is found.  When two or more objects compare equally, the returned object is unspecified. 

RELATED INFORMATION

Functions: hsearch(3), lsearch(3), qsort(3), tsearch(3). 

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