C Container Collection (CCC)
Loading...
Searching...
No Matches
priority_queue.h
Go to the documentation of this file.
1
18#ifndef CCC_PRIORITY_QUEUE_H
19#define CCC_PRIORITY_QUEUE_H
20
22#include <stdbool.h>
23#include <stddef.h>
26#include "impl/impl_priority_queue.h"
27#include "types.h"
28
39typedef struct ccc_pq_ ccc_priority_queue;
40
49typedef struct ccc_pq_elem_ ccc_pq_elem;
50
66#define ccc_pq_init(struct_name, pq_elem_field, pq_order, alloc_fn, cmp_fn, \
67 aux_data) \
68 ccc_impl_pq_init(struct_name, pq_elem_field, pq_order, alloc_fn, cmp_fn, \
69 aux_data)
70
88[[nodiscard]] void *ccc_pq_push(ccc_priority_queue *pq, ccc_pq_elem *elem);
89
98#define ccc_pq_emplace(priority_queue_ptr, lazy_value...) \
99 ccc_impl_pq_emplace(priority_queue_ptr, lazy_value)
100
105
113[[nodiscard]] void *ccc_pq_extract(ccc_priority_queue *pq, ccc_pq_elem *elem);
114
123
137 void *aux);
138
166#define ccc_pq_update_w(pq_ptr, pq_elem_ptr, update_closure_over_T...) \
167 ccc_impl_pq_update_w(pq_ptr, pq_elem_ptr, update_closure_over_T)
168
186 ccc_update_fn *fn, void *aux);
187
220#define ccc_pq_increase_w(pq_ptr, pq_elem_ptr, increase_closure_over_T...) \
221 ccc_impl_pq_increase_w(pq_ptr, pq_elem_ptr, increase_closure_over_T)
222
238 ccc_update_fn *fn, void *aux);
239
271#define ccc_pq_decrease_w(pq_ptr, pq_elem_ptr, decrease_closure_over_T...) \
272 ccc_impl_pq_decrease_w(pq_ptr, pq_elem_ptr, decrease_closure_over_T)
273
294
304[[nodiscard]] void *ccc_pq_front(ccc_priority_queue const *pq);
305
309[[nodiscard]] bool ccc_pq_is_empty(ccc_priority_queue const *pq);
310
314[[nodiscard]] size_t ccc_pq_size(ccc_priority_queue const *pq);
315
319[[nodiscard]] bool ccc_pq_validate(ccc_priority_queue const *pq);
320
325
330#ifdef PRIORITY_QUEUE_USING_NAMESPACE_CCC
331typedef ccc_pq_elem pq_elem;
332typedef ccc_priority_queue priority_queue;
333# define pq_init(args...) ccc_pq_init(args)
334# define pq_front(args...) ccc_pq_front(args)
335# define pq_push(args...) ccc_pq_push(args)
336# define pq_emplace(args...) ccc_pq_emplace(args)
337# define pq_pop(args...) ccc_pq_pop(args)
338# define pq_extract(args...) ccc_pq_extract(args)
339# define pq_is_empty(args...) ccc_pq_is_empty(args)
340# define pq_size(args...) ccc_pq_size(args)
341# define pq_update(args...) ccc_pq_update(args)
342# define pq_increase(args...) ccc_pq_increase(args)
343# define pq_decrease(args...) ccc_pq_decrease(args)
344# define pq_update_w(args...) ccc_pq_update_w(args)
345# define pq_increase_w(args...) ccc_pq_increase_w(args)
346# define pq_decrease_w(args...) ccc_pq_decrease_w(args)
347# define pq_order(args...) ccc_pq_order(args)
348# define pq_clear(args...) ccc_pq_clear(args)
349# define pq_validate(args...) ccc_pq_validate(args)
350#endif /* PRIORITY_QUEUE_USING_NAMESPACE_CCC */
351
352#endif /* CCC_PRIORITY_QUEUE_H */
void * ccc_pq_push(ccc_priority_queue *pq, ccc_pq_elem *elem)
Adds an element to the priority queue in correct total order. O(1).
void * ccc_pq_extract(ccc_priority_queue *pq, ccc_pq_elem *elem)
bool ccc_pq_update(ccc_priority_queue *pq, ccc_pq_elem *elem, ccc_update_fn *fn, void *aux)
Update the priority in the user type wrapping elem.
bool ccc_pq_decrease(ccc_priority_queue *pq, ccc_pq_elem *elem, ccc_update_fn *fn, void *aux)
Decreases the value of the type wrapping elem. O(1) or O(lgN)
struct ccc_pq_elem_ ccc_pq_elem
The embedded struct type for operation of the priority queue.
Definition: priority_queue.h:49
bool ccc_pq_is_empty(ccc_priority_queue const *pq)
Returns true if the priority queue is empty false if not. O(1).
ccc_result ccc_pq_erase(ccc_priority_queue *pq, ccc_pq_elem *elem)
Erase elem from the pq. Amortized O(lgN).
void * ccc_pq_front(ccc_priority_queue const *pq)
Obtain a reference to the front of the priority queue. O(1).
bool ccc_pq_validate(ccc_priority_queue const *pq)
Verifies the internal invariants of the pq hold.
size_t ccc_pq_size(ccc_priority_queue const *pq)
Returns the size of the priority queue.
ccc_result ccc_pq_clear(ccc_priority_queue *pq, ccc_destructor_fn *fn)
Removes all elements from the pq, freeing if needed.
ccc_threeway_cmp ccc_pq_order(ccc_priority_queue const *pq)
Return the order used to initialize the pq.
bool ccc_pq_increase(ccc_priority_queue *pq, ccc_pq_elem *elem, ccc_update_fn *fn, void *aux)
Increases the priority of the type wrapping elem. O(1) or O(lgN)
struct ccc_pq_ ccc_priority_queue
A container for pointer stability and an O(1) push and amortized o(lg N) increase/decrease key.
Definition: priority_queue.h:39
ccc_result ccc_pq_pop(ccc_priority_queue *pq)
Pops the front element from the priority queue. Amortized O(lgN).
The C Container Collection Fundamental Types.
ccc_result
A result of actions on containers.
Definition: types.h:65
void ccc_update_fn(ccc_user_type)
A callback function for modifying an element in the container.
Definition: types.h:216
ccc_threeway_cmp
A three-way comparison for comparison functions.
Definition: types.h:84
void ccc_destructor_fn(ccc_user_type)
A callback function for destroying an element in the container.
Definition: types.h:234