Git 2.5.2
[git/debian.git] / test-prio-queue.c
blob7be72f0086ba4b80cecf9f324bd5152a8531cdbd
1 #include "cache.h"
2 #include "prio-queue.h"
4 static int intcmp(const void *va, const void *vb, void *data)
6 const int *a = va, *b = vb;
7 return *a - *b;
10 static void show(int *v)
12 if (!v)
13 printf("NULL\n");
14 else
15 printf("%d\n", *v);
16 free(v);
19 int main(int argc, char **argv)
21 struct prio_queue pq = { intcmp };
23 while (*++argv) {
24 if (!strcmp(*argv, "get"))
25 show(prio_queue_get(&pq));
26 else if (!strcmp(*argv, "dump")) {
27 int *v;
28 while ((v = prio_queue_get(&pq)))
29 show(v);
31 else {
32 int *v = malloc(sizeof(*v));
33 *v = atoi(*argv);
34 prio_queue_put(&pq, v);
38 return 0;