typesafe_cb, hashtable: revise typesafe_cb arg order, neaten.
[ccan] / ccan / asearch / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * asearch - typesafe binary search (bsearch)
7  *
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).
10  *
11  * This version uses macros to be typesafe on platforms which support it.
12  *
13  * Licence: LGPL
14  *
15  * Example:
16  *      #include <ccan/asearch/asearch.h>
17  *      #include <stdio.h>
18  *      #include <string.h>
19  *      
20  *      static int cmp(const char *key, char *const *elem)
21  *      {
22  *              return strcmp(key, *elem);
23  *      }
24  *      
25  *      int main(int argc, char *argv[])
26  *      {
27  *              char **p;
28  *      
29  *              if (argc < 2) {
30  *                      fprintf(stderr, "Usage: %s <key> <list>...\n"
31  *                              "Print position of key in (sorted) list\n",
32  *                              argv[0]);
33  *                      exit(1);
34  *              }
35  *      
36  *              p = asearch(argv[1], &argv[2], argc-2, cmp);
37  *              if (!p) {
38  *                      printf("Not found!\n");
39  *                      return 1;
40  *              }
41  *              printf("%u\n", p - &argv[2]);
42  *              return 0;
43  *      }
44  */
45 int main(int argc, char *argv[])
46 {
47         if (argc != 2)
48                 return 1;
49
50         if (strcmp(argv[1], "depends") == 0) {
51                 printf("ccan/typesafe_cb\n");
52                 printf("ccan/array_size\n");
53                 return 0;
54         }
55
56         return 1;
57 }