49 #error Must define a SPECPQ_TAG to use this header
51 #ifndef SPECPQ_PRIORITY_TYPE
52 #error Must define a SPECPQ_PRIORITY_TYPE to use this header
54 #ifndef SPECPQ_DATA_TYPE
55 #error Must define a SPECPQ_DATA_TYPE to use this header
58 #define SPECPQ_PASTE_(x, y) x##y
59 #define SPECPQ_PASTE(x, y) SPECPQ_PASTE_(x, y)
61 #define SPECPQ_PQ struct SPECPQ_PASTE(SPECPQ_TAG, _pq)
62 #define SPECPQ_PQ_ struct SPECPQ_PASTE(SPECPQ_TAG, _pq_private_)
63 #define SPECPQ_CELL_ struct SPECPQ_PASTE(SPECPQ_TAG, _cell_private_)
64 #define SPECPQ_FOO(suffix) SPECPQ_PASTE(SPECPQ_TAG, suffix)
99 fc_malloc(
sizeof(*pq->cells) * initial_size));
100 pq->avail = initial_size;
101 pq->step = initial_size;
103 return reinterpret_cast<SPECPQ_PQ *
>(pq);
127 if (data_free !=
nullptr) {
128 for (i = 1; i < pq->size; i++) {
129 data_free(pq->cells[i].data);
147 if (pq->size >= pq->avail) {
148 int newsize = pq->size + pq->step;
151 fc_realloc(pq->cells,
sizeof(*pq->cells) * newsize));
157 while (i > 1 && (j = i / 2) && pq->cells[j].priority <
priority) {
158 pq->cells[i] = pq->cells[j];
161 pq->cells[i].data = data;
176 for (i = pq->size - 1; i >= 1; i--) {
177 if (pq->cells[i].data == data) {
185 }
else if (pq->cells[i].priority <
priority) {
187 while ((j = i / 2) && pq->cells[j].priority <
priority) {
188 pq->cells[i] = pq->cells[j];
191 pq->cells[i].data = data;
215 top = pq->cells[1].data;
217 tmp = pq->cells[pq->size];
220 pcelli = pq->cells + 1;
223 pcellj = pq->cells + j;
224 if (j < pq->
size && pcellj->priority < pq->cells[j + 1].priority) {
228 if (pcellj->priority <= tmp.priority) {
255 *pdata = pq->cells[1].data;
273 *ppriority = pq->cells[1].priority;
278 #undef SPECPQ_PRIORITY_TYPE
279 #undef SPECPQ_DATA_TYPE
#define fc_assert_ret_val(condition, val)
#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 SPECPQ_PQ *SPECPQ_FOO() _pq_new(int initial_size)
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 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)
#define fc_realloc(ptr, sz)