xref: /csrg-svn/lib/libc/stdlib/bsearch.3 (revision 66938)
1*66938Sbostic.\" Copyright (c) 1990, 1991, 1993, 1994
261180Sbostic.\"	The Regents of the University of California.  All rights reserved.
339301Sbostic.\"
450285Sbostic.\" This code is derived from software contributed to Berkeley by
550285Sbostic.\" the American National Standards Committee X3, on Information
650285Sbostic.\" Processing Systems.
750285Sbostic.\"
842125Sbostic.\" %sccs.include.redist.man%
939301Sbostic.\"
10*66938Sbostic.\"     @(#)bsearch.3	8.3 (Berkeley) 04/19/94
1139301Sbostic.\"
1248349Scael.Dd
1348349Scael.Dt BSEARCH 3
1448349Scael.Os
1548349Scael.Sh NAME
1648349Scael.Nm bsearch
1748349Scael.Nd binary search of a sorted table
1848349Scael.Sh SYNOPSIS
1948349Scael.Fd #include <stdlib.h>
2048349Scael.Ft void *
2148349Scael.Fn bsearch "const void *key" "const void *base" "size_t nmemb" "size_t size" "int (*compar) (const void *, const void *)"
2248349Scael.Sh DESCRIPTION
2339301SbosticThe
2448349Scael.Fn bsearch
2539301Sbosticfunction searches an array of
2648349Scael.Fa nmemb
27*66938Sbosticobjects, the initial member of which is
2839301Sbosticpointed to by
2948349Scael.Fa base ,
3039301Sbosticfor a member that matches the object pointed to by
3148349Scael.Fa key .
3239301SbosticThe size of each member of the array is specified by
3348349Scael.Fa size .
3448349Scael.Pp
3539301SbosticThe contents of the array should be in ascending sorted order according
3639301Sbosticto the comparison function referenced by
3748349Scael.Fa compar .
3848349ScaelThe
3948349Scael.Fa compar
4048349Scaelroutine
4165099Smckusickis expected to have
4248349Scaeltwo arguments which point to the
4348349Scael.Fa key
4448349Scaelobject and to an array member, in that order, and should return an integer
4539301Sbosticless than, equal to, or greater than zero if the
4648349Scael.Fa key
4748349Scaelobject is found, respectively, to be less than, to match, or be
4839301Sbosticgreater than the array member.
4948349Scael.Sh RETURN VALUES
5039301SbosticThe
5148349Scael.Fn bsearch
5239301Sbosticfunction returns a pointer to a matching member of the array, or a null
5339301Sbosticpointer if no match is found.
5439301SbosticIf two members compare as equal, which member is matched is unspecified.
5548349Scael.Sh SEE ALSO
5648376Scael.Xr db 3 ,
5748349Scael.Xr lsearch 3 ,
5848349Scael.Xr qsort 3 ,
5948349Scael.\" .Xr tsearch 3
6048349Scael.Sh STANDARDS
6148349ScaelThe
6248349Scael.Fn bsearch
6348349Scaelfunction conforms to
6448349Scael.St -ansiC .
65