_info 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "config.h"
  4. /**
  5. * asearch - typesafe binary search (bsearch)
  6. *
  7. * An ordered array of objects can be efficiently searched using a binary
  8. * search algorithm; the time taken is around log(number of elements).
  9. *
  10. * This version uses macros to be typesafe on platforms which support it.
  11. *
  12. * License: LGPL
  13. * Author: Rusty Russell <rusty@rustcorp.com.au>
  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", (int)(p - &argv[2]));
  42. * return 0;
  43. * }
  44. */
  45. int main(int argc, char *argv[])
  46. {
  47. if (argc != 2)
  48. return 1;
  49. if (strcmp(argv[1], "depends") == 0) {
  50. printf("ccan/typesafe_cb\n");
  51. return 0;
  52. }
  53. if (strcmp(argv[1], "testdepends") == 0) {
  54. printf("ccan/array_size\n");
  55. return 0;
  56. }
  57. return 1;
  58. }