1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-04 22:56:34 +02:00
git/t/helper/test-prio-queue.c
Elijah Newren 15db4e7f4a treewide: remove unnecessary cache.h includes in source files
We had several C files include cache.h unnecessarily.  Replace those
with an include of "git-compat-util.h" instead.  Much like the previous
commit, these have all been verified via both ensuring that
    gcc -E $SOURCE_FILE | grep '"cache.h"'
found no hits and that
    make DEVELOPER=1 ${OBJECT_FILE_FOR_SOURCE_FILE}
successfully compiles without warnings.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-02-23 17:25:28 -08:00

52 lines
980 B
C

#include "test-tool.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);
}
int cmd__prio_queue(int argc, const char **argv)
{
struct prio_queue pq = { intcmp };
while (*++argv) {
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 {
int *v = xmalloc(sizeof(*v));
*v = atoi(*argv);
prio_queue_put(&pq, v);
}
}
clear_prio_queue(&pq);
return 0;
}