59#error Must define a SPECPQ_TAG to use this header
61#ifndef SPECPQ_PRIORITY_TYPE
62#error Must define a SPECPQ_PRIORITY_TYPE to use this header
64#ifndef SPECPQ_DATA_TYPE
65#error Must define a SPECPQ_DATA_TYPE to use this header
68#define SPECPQ_PASTE_(x, y) x ## y
69#define SPECPQ_PASTE(x, y) SPECPQ_PASTE_(x, y)
71#define SPECPQ_PQ struct SPECPQ_PASTE(SPECPQ_TAG, _pq)
72#define SPECPQ_PQ_ struct SPECPQ_PASTE(SPECPQ_TAG, _pq_private_)
73#define SPECPQ_CELL_ struct SPECPQ_PASTE(SPECPQ_TAG, _cell_private_)
74#define SPECPQ_FOO(suffix) SPECPQ_PASTE(SPECPQ_TAG, suffix)
107 pq->cells =
fc_malloc(
sizeof(*pq->cells) * initial_size);
108 pq->avail = initial_size;
109 pq->step = initial_size;
135 if (data_free != NULL) {
136 for (i = 1; i < pq->size; i++) {
137 data_free(pq->cells[i].data);
155 if (pq->size >= pq->avail) {
156 int newsize = pq->size + pq->step;
158 pq->cells =
fc_realloc(pq->cells,
sizeof(*pq->cells) * newsize);
164 while (i > 1 && (j = i / 2) && pq->cells[j].priority <
priority) {
165 pq->cells[i] = pq->cells[j];
168 pq->cells[i].data = data;
183 for (i = pq->size - 1; i >= 1; i--) {
184 if (pq->cells[i].data == data) {
192 }
else if (pq->cells[i].priority <
priority) {
194 while ((j = i / 2) && pq->cells[j].priority <
priority) {
195 pq->cells[i] = pq->cells[j];
198 pq->cells[i].data = data;
222 top = pq->cells[1].data;
224 tmp = pq->cells[pq->size];
227 pcelli = pq->cells + 1;
231 pcellj = pq->cells + j;
232 if (j < pq->
size && pcellj->priority < pq->cells[j + 1].priority) {
236 if (pcellj->priority <= tmp.priority) {
264 *pdata = pq->cells[1].data;
281 *ppriority = pq->cells[1].priority;
286#undef SPECPQ_PRIORITY_TYPE
287#undef SPECPQ_DATA_TYPE
#define fc_assert_ret_val(condition, val)
#define fc_realloc(ptr, sz)
#define SPECPQ_PRIORITY_TYPE
#define SPECPQ_FOO(suffix)
static void SPECPQ_FOO() _pq_insert(SPECPQ_PQ *_pq, SPECPQ_DATA_TYPE data, SPECPQ_PRIORITY_TYPE priority)
static void SPECPQ_FOO() _pq_replace(SPECPQ_PQ *_pq, SPECPQ_DATA_TYPE data, SPECPQ_PRIORITY_TYPE priority)
static void SPECPQ_FOO() _pq_destroy(SPECPQ_PQ *_pq)
static bool SPECPQ_FOO() _pq_peek(const SPECPQ_PQ *_pq, SPECPQ_DATA_TYPE *pdata)
static void SPECPQ_FOO() _pq_destroy_full(SPECPQ_PQ *_pq, SPECPQ_FOO(_pq_data_free_fn_t) data_free)
SPECPQ_PRIORITY_TYPE priority
static SPECPQ_PQ *SPECPQ_FOO() _pq_new(int initial_size)
static bool SPECPQ_FOO() _pq_remove(SPECPQ_PQ *_pq, SPECPQ_DATA_TYPE *pdata)
static bool SPECPQ_FOO() _pq_priority(const SPECPQ_PQ *_pq, SPECPQ_PRIORITY_TYPE *ppriority)