]> git.ozlabs.org Git - ccan/blob - ccan/heap/_info
ccan: Correct some poor conventions in _info includes
[ccan] / ccan / heap / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * heap - a simple heap implementation
7  *
8  * Each heap entry is added as a void pointer. This means the implementation
9  * does _not_ assume you already have an array of entries. Instead, it keeps
10  * an internal array of pointers to those entries.
11  *
12  * Example:
13  *      #include <stdio.h>
14  *
15  *      #include <ccan/heap/heap.h>
16  *
17  *      static bool less(const int *i, const int *j)
18  *      {
19  *              return *i < *j;
20  *      }
21  *
22  *      static bool __less(const void *i, const void *j)
23  *      {
24  *              return less(i, j);
25  *      }
26  *
27  *      int main(int argc, char *argv[])
28  *      {
29  *              struct heap *h;
30  *              int arr[] = {1, 0, 2};
31  *              int i;
32  *
33  *              h = heap_init(__less);
34  *              if (h == NULL) {
35  *                      perror("heap alloc");
36  *                      exit(1);
37  *              }
38  *
39  *              for (i = 0; i < 3; i++) {
40  *                      if (heap_push(h, &arr[i])) {
41  *                              perror("heap push");
42  *                              exit(1);
43  *                      }
44  *              }
45  *              // should print 0, 1, 2
46  *              for (i = 0; i < 3; i++) {
47  *                      int *v = heap_pop(h);
48  *                      printf("%d\n", *v);
49  *              }
50  *              heap_free(h);
51  *              return 0;
52  *      }
53  *
54  * License: BSD-MIT
55  * Author: Emilio G. Cota <cota@braap.org>
56  */
57 int main(int argc, char *argv[])
58 {
59         /* Expect exactly one argument */
60         if (argc != 2)
61                 return 1;
62
63         if (strcmp(argv[1], "depends") == 0) {
64                 return 0;
65         }
66
67         return 1;
68 }