]>
Commit | Line | Data |
---|---|---|
1f2f436a A |
1 | --- bsearch.c.bsdnew 2009-11-13 14:11:48.000000000 -0800 |
2 | +++ bsearch.c 2009-11-13 14:11:48.000000000 -0800 | |
3 | @@ -77,3 +77,31 @@ bsearch(key, base0, nmemb, size, compar) | |
34e8f829 A |
4 | } |
5 | return (NULL); | |
6 | } | |
7 | + | |
8 | +#ifdef __BLOCKS__ | |
9 | +void * | |
10 | +bsearch_b(key, base0, nmemb, size, compar) | |
11 | + const void *key; | |
12 | + const void *base0; | |
13 | + size_t nmemb; | |
14 | + size_t size; | |
15 | + int (^compar)(const void *, const void *); | |
16 | +{ | |
17 | + const char *base = base0; | |
18 | + size_t lim; | |
19 | + int cmp; | |
20 | + const void *p; | |
21 | + | |
22 | + for (lim = nmemb; lim != 0; lim >>= 1) { | |
23 | + p = base + (lim >> 1) * size; | |
24 | + cmp = compar(key, p); | |
25 | + if (cmp == 0) | |
26 | + return ((void *)p); | |
27 | + if (cmp > 0) { /* key > p: move right */ | |
28 | + base = (char *)p + size; | |
29 | + lim--; | |
30 | + } /* else move left */ | |
31 | + } | |
32 | + return (NULL); | |
33 | +} | |
34 | +#endif /* __BLOCKS__ */ |