6 * asearch - typesafe binary search (bsearch)
8 * An ordered array of objects can be efficiently searched using a binary
9 * search algorithm; the time taken is around log(number of elements).
11 * This version uses macros to be typesafe on platforms which support it.
14 * Author: Rusty Russell <rusty@rustcorp.com.au>
17 * #include <ccan/asearch/asearch.h>
21 * static int cmp(const char *key, char *const *elem)
23 * return strcmp(key, *elem);
26 * int main(int argc, char *argv[])
31 * fprintf(stderr, "Usage: %s <key> <list>...\n"
32 * "Print position of key in (sorted) list\n",
37 * p = asearch(argv[1], &argv[2], argc-2, cmp);
39 * printf("Not found!\n");
42 * printf("%u\n", p - &argv[2]);
46 int main(int argc, char *argv[])
51 if (strcmp(argv[1], "depends") == 0) {
52 printf("ccan/typesafe_cb\n");
53 printf("ccan/array_size\n");