t/helper: merge test-prio-queue into test-tool
[git/git.git] / t / helper / test-prio-queue.c
CommitLineData
15b75817 1#include "test-tool.h"
b4b594a3
JH
2#include "cache.h"
3#include "prio-queue.h"
4
5static int intcmp(const void *va, const void *vb, void *data)
6{
7 const int *a = va, *b = vb;
8 return *a - *b;
9}
10
11static void show(int *v)
12{
13 if (!v)
14 printf("NULL\n");
15 else
16 printf("%d\n", *v);
17 free(v);
18}
19
15b75817 20int cmd__prio_queue(int argc, const char **argv)
b4b594a3
JH
21{
22 struct prio_queue pq = { intcmp };
23
24 while (*++argv) {
25 if (!strcmp(*argv, "get"))
26 show(prio_queue_get(&pq));
27 else if (!strcmp(*argv, "dump")) {
28 int *v;
29 while ((v = prio_queue_get(&pq)))
30 show(v);
31 }
32 else {
33 int *v = malloc(sizeof(*v));
34 *v = atoi(*argv);
35 prio_queue_put(&pq, v);
36 }
37 }
38
39 return 0;
40}