2018-03-24 07:44:50 +00:00
|
|
|
#include "test-tool.h"
|
2013-06-07 02:13:50 +00:00
|
|
|
#include "cache.h"
|
|
|
|
#include "prio-queue.h"
|
|
|
|
|
|
|
|
static int intcmp(const void *va, const void *vb, void *data)
|
|
|
|
{
|
|
|
|
const int *a = va, *b = vb;
|
|
|
|
return *a - *b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show(int *v)
|
|
|
|
{
|
|
|
|
if (!v)
|
|
|
|
printf("NULL\n");
|
|
|
|
else
|
|
|
|
printf("%d\n", *v);
|
|
|
|
free(v);
|
|
|
|
}
|
|
|
|
|
2018-03-24 07:44:50 +00:00
|
|
|
int cmd__prio_queue(int argc, const char **argv)
|
2013-06-07 02:13:50 +00:00
|
|
|
{
|
|
|
|
struct prio_queue pq = { intcmp };
|
|
|
|
|
|
|
|
while (*++argv) {
|
2018-11-01 13:46:17 +00:00
|
|
|
if (!strcmp(*argv, "get")) {
|
|
|
|
void *peek = prio_queue_peek(&pq);
|
|
|
|
void *get = prio_queue_get(&pq);
|
|
|
|
if (peek != get)
|
|
|
|
BUG("peek and get results do not match");
|
|
|
|
show(get);
|
|
|
|
} else if (!strcmp(*argv, "dump")) {
|
|
|
|
void *peek;
|
|
|
|
void *get;
|
|
|
|
while ((peek = prio_queue_peek(&pq))) {
|
|
|
|
get = prio_queue_get(&pq);
|
|
|
|
if (peek != get)
|
|
|
|
BUG("peek and get results do not match");
|
|
|
|
show(get);
|
|
|
|
}
|
|
|
|
} else if (!strcmp(*argv, "stack")) {
|
|
|
|
pq.compare = NULL;
|
|
|
|
} else {
|
2019-04-11 13:48:14 +00:00
|
|
|
int *v = xmalloc(sizeof(*v));
|
2013-06-07 02:13:50 +00:00
|
|
|
*v = atoi(*argv);
|
|
|
|
prio_queue_put(&pq, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-07 10:01:31 +00:00
|
|
|
clear_prio_queue(&pq);
|
|
|
|
|
2013-06-07 02:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|