]> git.ozlabs.org Git - ccan/blob - ccan/asearch/_info
ccanlint: ignore comments when parsing examples.
[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  * License: LGPL
14  * Author: Rusty Russell <rusty@rustcorp.com.au>
15  *
16  * Example:
17  *      #include <ccan/asearch/asearch.h>
18  *      #include <stdio.h>
19  *      #include <string.h>
20  *      
21  *      static int cmp(const char *key, char *const *elem)
22  *      {
23  *              return strcmp(key, *elem);
24  *      }
25  *      
26  *      int main(int argc, char *argv[])
27  *      {
28  *              char **p;
29  *      
30  *              if (argc < 2) {
31  *                      fprintf(stderr, "Usage: %s <key> <list>...\n"
32  *                              "Print position of key in (sorted) list\n",
33  *                              argv[0]);
34  *                      exit(1);
35  *              }
36  *      
37  *              p = asearch(argv[1], &argv[2], argc-2, cmp);
38  *              if (!p) {
39  *                      printf("Not found!\n");
40  *                      return 1;
41  *              }
42  *              printf("%u\n", p - &argv[2]);
43  *              return 0;
44  *      }
45  */
46 int main(int argc, char *argv[])
47 {
48         if (argc != 2)
49                 return 1;
50
51         if (strcmp(argv[1], "depends") == 0) {
52                 printf("ccan/typesafe_cb\n");
53                 printf("ccan/array_size\n");
54                 return 0;
55         }
56
57         return 1;
58 }