Commit | Line | Data |
---|---|---|
ae59e04c | 1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
a74efd49 KB |
2 | .\" All rights reserved. |
3 | .\" | |
d17d385d | 4 | .\" %sccs.include.redist.man% |
a74efd49 | 5 | .\" |
ae59e04c | 6 | .\" @(#)bsearch.3 5.4 (Berkeley) %G% |
a74efd49 | 7 | .\" |
ae59e04c CL |
8 | .Dd |
9 | .Dt BSEARCH 3 | |
10 | .Os | |
11 | .Sh NAME | |
12 | .Nm bsearch | |
13 | .Nd binary search of a sorted table | |
14 | .Sh SYNOPSIS | |
15 | .Fd #include <stdlib.h> | |
16 | .Ft void * | |
17 | .Fn bsearch "const void *key" "const void *base" "size_t nmemb" "size_t size" "int (*compar) (const void *, const void *)" | |
18 | .Sh DESCRIPTION | |
a74efd49 | 19 | The |
ae59e04c | 20 | .Fn bsearch |
a74efd49 | 21 | function searches an array of |
ae59e04c | 22 | .Fa nmemb |
a74efd49 KB |
23 | objects, the inital member of which is |
24 | pointed to by | |
ae59e04c | 25 | .Fa base , |
a74efd49 | 26 | for a member that matches the object pointed to by |
ae59e04c | 27 | .Fa key . |
a74efd49 | 28 | The size of each member of the array is specified by |
ae59e04c CL |
29 | .Fa size . |
30 | .Pp | |
a74efd49 KB |
31 | The contents of the array should be in ascending sorted order according |
32 | to the comparison function referenced by | |
ae59e04c CL |
33 | .Fa compar . |
34 | The | |
35 | .Fa compar | |
36 | routine | |
37 | is expected to have two | |
38 | two arguments which point to the | |
39 | .Fa key | |
40 | object and to an array member, in that order, and should return an integer | |
a74efd49 | 41 | less than, equal to, or greater than zero if the |
ae59e04c CL |
42 | .Fa key |
43 | object is found, respectively, to be less than, to match, or be | |
a74efd49 | 44 | greater than the array member. |
ae59e04c | 45 | .Sh RETURN VALUES |
a74efd49 | 46 | The |
ae59e04c | 47 | .Fn bsearch |
a74efd49 KB |
48 | function returns a pointer to a matching member of the array, or a null |
49 | pointer if no match is found. | |
50 | If two members compare as equal, which member is matched is unspecified. | |
ae59e04c CL |
51 | .Sh SEE ALSO |
52 | .Xr hsearch 3 , | |
53 | .Xr lsearch 3 , | |
54 | .Xr qsort 3 , | |
55 | .\" .Xr tsearch 3 | |
56 | .Sh STANDARDS | |
57 | The | |
58 | .Fn bsearch | |
59 | function conforms to | |
60 | .St -ansiC . |