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