]>
Commit | Line | Data |
---|---|---|
15b75817 | 1 | #include "test-tool.h" |
b4b594a3 JH |
2 | #include "cache.h" |
3 | #include "prio-queue.h" | |
4 | ||
5 | static int intcmp(const void *va, const void *vb, void *data) | |
6 | { | |
7 | const int *a = va, *b = vb; | |
8 | return *a - *b; | |
9 | } | |
10 | ||
11 | static 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 | 20 | int cmd__prio_queue(int argc, const char **argv) |
b4b594a3 JH |
21 | { |
22 | struct prio_queue pq = { intcmp }; | |
23 | ||
24 | while (*++argv) { | |
aca4240f DS |
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); | |
39 | } | |
40 | } else if (!strcmp(*argv, "stack")) { | |
41 | pq.compare = NULL; | |
42 | } else { | |
73a5faf0 | 43 | int *v = xmalloc(sizeof(*v)); |
b4b594a3 JH |
44 | *v = atoi(*argv); |
45 | prio_queue_put(&pq, v); | |
46 | } | |
47 | } | |
48 | ||
6a75658c ÆAB |
49 | clear_prio_queue(&pq); |
50 | ||
b4b594a3 JH |
51 | return 0; |
52 | } |