xref: /csrg-svn/lib/libc/stdlib/bsearch.3 (revision 48376)
148349Scael.\" Copyright (c) 1990, 1991 The Regents of the University of California.
239301Sbostic.\" All rights reserved.
339301Sbostic.\"
442125Sbostic.\" %sccs.include.redist.man%
539301Sbostic.\"
6*48376Scael.\"     @(#)bsearch.3	5.5 (Berkeley) 04/20/91
739301Sbostic.\"
848349Scael.Dd
948349Scael.Dt BSEARCH 3
1048349Scael.Os
1148349Scael.Sh NAME
1248349Scael.Nm bsearch
1348349Scael.Nd binary search of a sorted table
1448349Scael.Sh SYNOPSIS
1548349Scael.Fd #include <stdlib.h>
1648349Scael.Ft void *
1748349Scael.Fn bsearch "const void *key" "const void *base" "size_t nmemb" "size_t size" "int (*compar) (const void *, const void *)"
1848349Scael.Sh DESCRIPTION
1939301SbosticThe
2048349Scael.Fn bsearch
2139301Sbosticfunction searches an array of
2248349Scael.Fa nmemb
2339301Sbosticobjects, the inital member of which is
2439301Sbosticpointed to by
2548349Scael.Fa base ,
2639301Sbosticfor a member that matches the object pointed to by
2748349Scael.Fa key .
2839301SbosticThe size of each member of the array is specified by
2948349Scael.Fa size .
3048349Scael.Pp
3139301SbosticThe contents of the array should be in ascending sorted order according
3239301Sbosticto the comparison function referenced by
3348349Scael.Fa compar .
3448349ScaelThe
3548349Scael.Fa compar
3648349Scaelroutine
3748349Scaelis expected to have two
3848349Scaeltwo arguments which point to the
3948349Scael.Fa key
4048349Scaelobject and to an array member, in that order, and should return an integer
4139301Sbosticless than, equal to, or greater than zero if the
4248349Scael.Fa key
4348349Scaelobject is found, respectively, to be less than, to match, or be
4439301Sbosticgreater than the array member.
4548349Scael.Sh RETURN VALUES
4639301SbosticThe
4748349Scael.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.
5148349Scael.Sh SEE ALSO
52*48376Scael.Xr db 3 ,
5348349Scael.Xr lsearch 3 ,
5448349Scael.Xr qsort 3 ,
5548349Scael.\" .Xr tsearch 3
5648349Scael.Sh STANDARDS
5748349ScaelThe
5848349Scael.Fn bsearch
5948349Scaelfunction conforms to
6048349Scael.St -ansiC .
61