| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "basic-forward.h" |
| 5 |
|
| 6 |
typedef struct Prioq Prioq; |
| 7 |
|
| 8 |
#define PRIOQ_IDX_NULL (UINT_MAX) |
| 9 |
|
| 10 |
Prioq* prioq_new(compare_func_t compare); |
| 11 |
Prioq* prioq_free(Prioq *q); |
| 12 |
DEFINE_TRIVIAL_CLEANUP_FUNC(Prioq*, prioq_free); |
| 13 |
int prioq_ensure_allocated(Prioq **q, compare_func_t compare_func); |
| 14 |
|
| 15 |
int prioq_put(Prioq *q, void *data, unsigned *idx); |
| 16 |
int _prioq_ensure_put(Prioq **q, compare_func_t compare_func, void *data, unsigned *idx); |
| 17 |
#define prioq_ensure_put(q, compare_func, data, idx) \ |
| 18 |
({ \ |
| 19 |
int (*_func_)(const typeof((data)[0])*, const typeof((data)[0])*) = compare_func; \ |
| 20 |
_prioq_ensure_put(q, (compare_func_t) _func_, data, idx); \ |
| 21 |
}) |
| 22 |
|
| 23 |
int prioq_remove(Prioq *q, void *data, unsigned *idx); |
| 24 |
void prioq_reshuffle(Prioq *q, void *data, unsigned *idx); |
| 25 |
|
| 26 |
void* prioq_peek_by_index(Prioq *q, unsigned idx) _pure_; |
| 27 |
static inline void *prioq_peek(Prioq *q) { |
| 28 |
return prioq_peek_by_index(q, 0); |
| 29 |
} |
| 30 |
void* prioq_pop(Prioq *q); |
| 31 |
|
| 32 |
#define PRIOQ_FOREACH_ITEM(q, p) \ |
| 33 |
for (unsigned _i = 0; (p = prioq_peek_by_index(q, _i)); _i++) |
| 34 |
|
| 35 |
unsigned prioq_size(Prioq *q) _pure_; |
| 36 |
bool prioq_isempty(Prioq *q) _pure_; |