4 * This is something I found on watmath. I've made some minor changes for use
12 static char *RCSid = "$OHeader: /usr/mfcf/src/accounts/libuw/RCS/bsearch.c,v 1.1 88/06/11 20:41:48 root Exp $";
21 static char const SCCSid[] = "@(#) mytinfo bsearch.c 3.4 92/06/04 public domain, By Ross Ridge";
24 #ifdef USE_SHORT_BSEARCH
25 #define fast_int short
27 #define fast_int mysize_t
31 * bsearch - find an element of a sorted vector
33 * found = bsearch(key, array, dimension, width, compare)
34 * returns a pointer to the specified element in the array,
35 * or (char*)0 if the element can't be found.
37 * pointer to the element to be searched for in the array
39 * address of an array of elements
41 * number of elements in the array
43 * sizeof(type) of each element
45 * pointer to a function taking (char *) pointers to two elements
46 * and returning <0, 0, or >0 as the first element comes before,
47 * at, or after the second element. A compare function is provided
48 * for comparing strings.
52 * $OLog: bsearch.c,v $
53 * Revision 1.1 88/06/11 20:41:48 root
60 bsearch(key, array, dimension, iwidth, compare)
67 register fast_int start; /* offset to start of current interval */
68 register fast_int end; /* offset to end+1 of current interval */
69 register fast_int middle; /* offset to middle of current interval */
71 register fast_int width;
73 width = iwidth / sizeof(char);
81 middle = (start + end) / 2;
83 status = (*compare)(key, ((char *)array + middle*width));
91 else return (anyptr)(((char *)array) + middle*width);
97 #endif /* USE_MYBSEARCH */