t / helper / test-prio-queue.con commit Merge branch 'sb/submodule-clone-retry' (2f9c615)
   1#include "cache.h"
   2#include "prio-queue.h"
   3
   4static int intcmp(const void *va, const void *vb, void *data)
   5{
   6        const int *a = va, *b = vb;
   7        return *a - *b;
   8}
   9
  10static void show(int *v)
  11{
  12        if (!v)
  13                printf("NULL\n");
  14        else
  15                printf("%d\n", *v);
  16        free(v);
  17}
  18
  19int cmd_main(int argc, const char **argv)
  20{
  21        struct prio_queue pq = { intcmp };
  22
  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);
  30                }
  31                else {
  32                        int *v = malloc(sizeof(*v));
  33                        *v = atoi(*argv);
  34                        prio_queue_put(&pq, v);
  35                }
  36        }
  37
  38        return 0;
  39}