dir: fix treatment of negated pathspecs
[git/raj.git] / t / helper / test-prio-queue.c
blobf4028442e37e39d7ec35abf00c237d4d2cbac892
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "prio-queue.h"
5 static int intcmp(const void *va, const void *vb, void *data)
7 const int *a = va, *b = vb;
8 return *a - *b;
11 static void show(int *v)
13 if (!v)
14 printf("NULL\n");
15 else
16 printf("%d\n", *v);
17 free(v);
20 int cmd__prio_queue(int argc, const char **argv)
22 struct prio_queue pq = { intcmp };
24 while (*++argv) {
25 if (!strcmp(*argv, "get")) {
26 void *peek = prio_queue_peek(&pq);
27 void *get = prio_queue_get(&pq);
28 if (peek != get)
29 BUG("peek and get results do not match");
30 show(get);
31 } else if (!strcmp(*argv, "dump")) {
32 void *peek;
33 void *get;
34 while ((peek = prio_queue_peek(&pq))) {
35 get = prio_queue_get(&pq);
36 if (peek != get)
37 BUG("peek and get results do not match");
38 show(get);
40 } else if (!strcmp(*argv, "stack")) {
41 pq.compare = NULL;
42 } else {
43 int *v = xmalloc(sizeof(*v));
44 *v = atoi(*argv);
45 prio_queue_put(&pq, v);
49 return 0;