1 #include "sparse_bsearch.h"
3 void *_sparse_bsearch(const void *key, const void *base,
4 size_t nmemb, size_t size,
5 int (*cmpfn)(const void *, const void *),
6 bool (*validfn)(const void *))
8 ssize_t start = 0, end = nmemb - 1;
11 while (start <= end) {
12 ssize_t next = (start + end) / 2;
15 while (!validfn(p + next * size)) {
16 /* Try the next one along. */
19 /* Hmm, none of these were valid. */
20 next = (start + end) / 2;
25 result = cmpfn(key, p + next * size);
27 return (void *)(p + next * size);