1 /* SPDX-License-Identifier: LGPL-2.1+ */
9 typedef struct Prioq Prioq
;
11 #define PRIOQ_IDX_NULL ((unsigned) -1)
13 Prioq
*prioq_new(compare_func_t compare
);
14 Prioq
*prioq_free(Prioq
*q
);
15 DEFINE_TRIVIAL_CLEANUP_FUNC(Prioq
*, prioq_free
);
16 int prioq_ensure_allocated(Prioq
**q
, compare_func_t compare_func
);
18 int prioq_put(Prioq
*q
, void *data
, unsigned *idx
);
19 int prioq_remove(Prioq
*q
, void *data
, unsigned *idx
);
20 int prioq_reshuffle(Prioq
*q
, void *data
, unsigned *idx
);
22 void *prioq_peek_by_index(Prioq
*q
, unsigned idx
) _pure_
;
23 static inline void *prioq_peek(Prioq
*q
) {
24 return prioq_peek_by_index(q
, 0);
26 void *prioq_pop(Prioq
*q
);
28 #define PRIOQ_FOREACH_ITEM(q, p) \
29 for (unsigned _i = 0; (p = prioq_peek_by_index(q, _i)); _i++)
31 unsigned prioq_size(Prioq
*q
) _pure_
;
32 bool prioq_isempty(Prioq
*q
) _pure_
;