priorityq.c revision 9afebd21ced1d43f638e08a1411c9a89e526231f
/* Copyright (c) 2008 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "priorityq.h"
/* Macros for moving inside an array implementation of binary tree where
[0] is the root. */
#define PARENT_IDX(idx) \
#define LEFT_CHILD_IDX(idx) \
#define RIGHT_CHILD_IDX(idx) \
struct priorityq {
};
struct priorityq *
{
return pq;
}
{
}
{
}
{
struct priorityq_item *tmp;
/* swap the item indexes */
/* swap the item pointers */
}
static unsigned int
{
struct priorityq_item **items;
unsigned int parent_idx;
while (idx > 0) {
break;
/* wrong order - swap */
idx = parent_idx;
}
return idx;
}
{
struct priorityq_item **items;
else
break;
/* wrong order - swap */
idx = min_child_idx;
}
}
{
}
{
struct priorityq_item **items;
unsigned int count;
/* move last item over the removed one and fix the heap */
count--;
if (count > 0) {
if (idx > 0)
}
}
{
}
{
struct priorityq_item *const *items;
return NULL;
return items[0];
}
{
struct priorityq_item *item;
priorityq_remove_idx(pq, 0);
return item;
}