xref: /csrg-svn/lib/libc/stdlib/bsearch.3 (revision 48349)
1*48349Scael.\" Copyright (c) 1990, 1991 The Regents of the University of California.
239301Sbostic.\" All rights reserved.
339301Sbostic.\"
442125Sbostic.\" %sccs.include.redist.man%
539301Sbostic.\"
6*48349Scael.\"     @(#)bsearch.3	5.4 (Berkeley) 04/19/91
739301Sbostic.\"
8*48349Scael.Dd
9*48349Scael.Dt BSEARCH 3
10*48349Scael.Os
11*48349Scael.Sh NAME
12*48349Scael.Nm bsearch
13*48349Scael.Nd binary search of a sorted table
14*48349Scael.Sh SYNOPSIS
15*48349Scael.Fd #include <stdlib.h>
16*48349Scael.Ft void *
17*48349Scael.Fn bsearch "const void *key" "const void *base" "size_t nmemb" "size_t size" "int (*compar) (const void *, const void *)"
18*48349Scael.Sh DESCRIPTION
1939301SbosticThe
20*48349Scael.Fn bsearch
2139301Sbosticfunction searches an array of
22*48349Scael.Fa nmemb
2339301Sbosticobjects, the inital member of which is
2439301Sbosticpointed to by
25*48349Scael.Fa base ,
2639301Sbosticfor a member that matches the object pointed to by
27*48349Scael.Fa key .
2839301SbosticThe size of each member of the array is specified by
29*48349Scael.Fa size .
30*48349Scael.Pp
3139301SbosticThe contents of the array should be in ascending sorted order according
3239301Sbosticto the comparison function referenced by
33*48349Scael.Fa compar .
34*48349ScaelThe
35*48349Scael.Fa compar
36*48349Scaelroutine
37*48349Scaelis expected to have two
38*48349Scaeltwo arguments which point to the
39*48349Scael.Fa key
40*48349Scaelobject and to an array member, in that order, and should return an integer
4139301Sbosticless than, equal to, or greater than zero if the
42*48349Scael.Fa key
43*48349Scaelobject is found, respectively, to be less than, to match, or be
4439301Sbosticgreater than the array member.
45*48349Scael.Sh RETURN VALUES
4639301SbosticThe
47*48349Scael.Fn bsearch
4839301Sbosticfunction returns a pointer to a matching member of the array, or a null
4939301Sbosticpointer if no match is found.
5039301SbosticIf two members compare as equal, which member is matched is unspecified.
51*48349Scael.Sh SEE ALSO
52*48349Scael.Xr hsearch 3 ,
53*48349Scael.Xr lsearch 3 ,
54*48349Scael.Xr qsort 3 ,
55*48349Scael.\" .Xr tsearch 3
56*48349Scael.Sh STANDARDS
57*48349ScaelThe
58*48349Scael.Fn bsearch
59*48349Scaelfunction conforms to
60*48349Scael.St -ansiC .
61