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 <stddef.h>
25#include "impl/impl_priority_queue.h"
26#include "types.h"
27
38typedef struct ccc_pq_ ccc_priority_queue;
39
48typedef struct ccc_pq_elem_ ccc_pq_elem;
49
65#define ccc_pq_init(struct_name, pq_elem_field, pq_order, cmp_fn, alloc_fn, \
66 aux_data) \
67 ccc_impl_pq_init(struct_name, pq_elem_field, pq_order, cmp_fn, alloc_fn, \
68 aux_data)
69
87[[nodiscard]] void *ccc_pq_push(ccc_priority_queue *pq, ccc_pq_elem *elem);
88
97#define ccc_pq_emplace(priority_queue_ptr, lazy_value...) \
98 ccc_impl_pq_emplace(priority_queue_ptr, lazy_value)
99
104
112[[nodiscard]] void *ccc_pq_extract(ccc_priority_queue *pq, ccc_pq_elem *elem);
113
122
136 ccc_update_fn *fn, void *aux);
137
165#define ccc_pq_update_w(pq_ptr, pq_elem_ptr, update_closure_over_T...) \
166 ccc_impl_pq_update_w(pq_ptr, pq_elem_ptr, update_closure_over_T)
167
185 ccc_update_fn *fn, void *aux);
186
219#define ccc_pq_increase_w(pq_ptr, pq_elem_ptr, increase_closure_over_T...) \
220 ccc_impl_pq_increase_w(pq_ptr, pq_elem_ptr, increase_closure_over_T)
221
237 ccc_update_fn *fn, void *aux);
238
270#define ccc_pq_decrease_w(pq_ptr, pq_elem_ptr, decrease_closure_over_T...) \
271 ccc_impl_pq_decrease_w(pq_ptr, pq_elem_ptr, decrease_closure_over_T)
272
293
303[[nodiscard]] void *ccc_pq_front(ccc_priority_queue const *pq);
304
309
314
319
324
329#ifdef PRIORITY_QUEUE_USING_NAMESPACE_CCC
330typedef ccc_pq_elem pq_elem;
331typedef ccc_priority_queue priority_queue;
332# define pq_init(args...) ccc_pq_init(args)
333# define pq_front(args...) ccc_pq_front(args)
334# define pq_push(args...) ccc_pq_push(args)
335# define pq_emplace(args...) ccc_pq_emplace(args)
336# define pq_pop(args...) ccc_pq_pop(args)
337# define pq_extract(args...) ccc_pq_extract(args)
338# define pq_is_empty(args...) ccc_pq_is_empty(args)
339# define pq_size(args...) ccc_pq_size(args)
340# define pq_update(args...) ccc_pq_update(args)
341# define pq_increase(args...) ccc_pq_increase(args)
342# define pq_decrease(args...) ccc_pq_decrease(args)
343# define pq_update_w(args...) ccc_pq_update_w(args)
344# define pq_increase_w(args...) ccc_pq_increase_w(args)
345# define pq_decrease_w(args...) ccc_pq_decrease_w(args)
346# define pq_order(args...) ccc_pq_order(args)
347# define pq_clear(args...) ccc_pq_clear(args)
348# define pq_validate(args...) ccc_pq_validate(args)
349#endif /* PRIORITY_QUEUE_USING_NAMESPACE_CCC */
350
351#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)
struct ccc_pq_elem_ ccc_pq_elem
The embedded struct type for operation of the priority queue.
Definition: priority_queue.h:48
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).
ccc_ucount ccc_pq_size(ccc_priority_queue const *pq)
Returns the size of the priority queue.
ccc_tribool ccc_pq_validate(ccc_priority_queue const *pq)
Verifies the internal invariants of the pq hold.
ccc_tribool ccc_pq_is_empty(ccc_priority_queue const *pq)
Returns true if the priority queue is empty false if not. O(1).
ccc_tribool 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.
ccc_tribool 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)
ccc_tribool 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)
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.
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:38
ccc_result ccc_pq_pop(ccc_priority_queue *pq)
Pops the front element from the priority queue. Amortized O(lgN).
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:172
The C Container Collection Fundamental Types.
void ccc_update_fn(ccc_user_type)
A callback function for modifying an element in the container.
Definition: types.h:300
ccc_result
A result of actions on containers.
Definition: types.h:117
ccc_tribool
A three state boolean to allow for an error state. Error is -1, False is 0, and True is 1.
Definition: types.h:102
void ccc_destructor_fn(ccc_user_type)
A callback function for destroying an element in the container.
Definition: types.h:318
ccc_threeway_cmp
A three-way comparison for comparison functions.
Definition: types.h:138