C Container Collection (CCC)
Loading...
Searching...
No Matches
flat_priority_queue.h
Go to the documentation of this file.
1
16#ifndef CCC_FLAT_PRIORITY_QUEUE_H
17#define CCC_FLAT_PRIORITY_QUEUE_H
18
20#include <stddef.h>
23#include "impl/impl_flat_priority_queue.h"
24#include "types.h"
25
36typedef struct ccc_fpq_ ccc_flat_priority_queue;
37
57#define ccc_fpq_init(mem_ptr, cmp_order, cmp_fn, alloc_fn, aux_data, capacity) \
58 ccc_impl_fpq_init(mem_ptr, cmp_order, cmp_fn, alloc_fn, aux_data, capacity)
59
74#define ccc_fpq_heapify_init(mem_ptr, cmp_order, cmp_fn, alloc_fn, aux_data, \
75 capacity, size) \
76 ccc_impl_fpq_heapify_init(mem_ptr, cmp_order, cmp_fn, alloc_fn, aux_data, \
77 capacity, size)
78
144 ccc_flat_priority_queue const *src, ccc_alloc_fn *fn);
145
156#define ccc_fpq_emplace(fpq, val_initializer...) \
157 ccc_impl_fpq_emplace(fpq, val_initializer)
158
174 size_t input_n, size_t input_elem_size);
175
186
193 ccc_alloc_fn *fn);
194
201[[nodiscard]] void *ccc_fpq_push(ccc_flat_priority_queue *fpq, void const *e);
202
207
217
227 void *aux);
228
248#define ccc_fpq_update_w(fpq_ptr, T_ptr, update_closure_over_T...) \
249 ccc_impl_fpq_update_w(fpq_ptr, T_ptr, update_closure_over_T)
250
260 void *aux);
261
281#define ccc_fpq_increase_w(fpq_ptr, T_ptr, increase_closure_over_T...) \
282 ccc_impl_fpq_increase_w(fpq_ptr, T_ptr, increase_closure_over_T)
283
293 void *aux);
294
314#define ccc_fpq_decrease_w(fpq_ptr, T_ptr, decrease_closure_over_T...) \
315 ccc_impl_fpq_decrease_w(fpq_ptr, T_ptr, decrease_closure_over_T)
316
335
351
361[[nodiscard]] void *ccc_fpq_front(ccc_flat_priority_queue const *fpq);
362
367
372
377
385[[nodiscard]] void *ccc_fpq_data(ccc_flat_priority_queue const *fpq);
386
391
395[[nodiscard]] ccc_threeway_cmp
397
402#ifdef FLAT_PRIORITY_QUEUE_USING_NAMESPACE_CCC
403typedef ccc_flat_priority_queue flat_priority_queue;
404# define fpq_init(args...) ccc_fpq_init(args)
405# define fpq_heapify_init(args...) ccc_fpq_heapify_init(args)
406# define fpq_copy(args...) ccc_fpq_copy(args)
407# define fpq_heapify(args...) ccc_fpq_heapify(args)
408# define fpq_emplace(args...) ccc_fpq_emplace(args)
409# define fpq_realloc(args...) ccc_fpq_realloc(args)
410# define fpq_push(args...) ccc_fpq_push(args)
411# define fpq_front(args...) ccc_fpq_front(args)
412# define fpq_i(args...) ccc_fpq_i(args)
413# define fpq_pop(args...) ccc_fpq_pop(args)
414# define fpq_extract(args...) ccc_fpq_extract(args)
415# define fpq_update(args...) ccc_fpq_update(args)
416# define fpq_increase(args...) ccc_fpq_increase(args)
417# define fpq_decrease(args...) ccc_fpq_decrease(args)
418# define fpq_update_w(args...) ccc_fpq_update_w(args)
419# define fpq_increase_w(args...) ccc_fpq_increase_w(args)
420# define fpq_decrease_w(args...) ccc_fpq_decrease_w(args)
421# define fpq_clear(args...) ccc_fpq_clear(args)
422# define fpq_clear_and_free(args...) ccc_fpq_clear_and_free(args)
423# define fpq_is_empty(args...) ccc_fpq_is_empty(args)
424# define fpq_size(args...) ccc_fpq_size(args)
425# define fpq_data(args...) ccc_fpq_data(args)
426# define fpq_validate(args...) ccc_fpq_validate(args)
427# define fpq_order(args...) ccc_fpq_order(args)
428#endif /* FLAT_PRIORITY_QUEUE_USING_NAMESPACE_CCC */
429
430#endif /* CCC_FLAT_PRIORITY_QUEUE_H */
void * ccc_fpq_data(ccc_flat_priority_queue const *fpq)
Return a pointer to the base of the backing array. O(1).
ccc_result ccc_fpq_copy(ccc_flat_priority_queue *dst, ccc_flat_priority_queue const *src, ccc_alloc_fn *fn)
Copy the fpq from src to newly initialized dst.
ccc_tribool ccc_fpq_is_empty(ccc_flat_priority_queue const *fpq)
Returns true if the fpq is empty false if not. O(1).
ccc_result ccc_fpq_heapify_inplace(ccc_flat_priority_queue *fpq, size_t n)
Order n elements of the underlying fpq buffer as an fpq.
ccc_result ccc_fpq_clear(ccc_flat_priority_queue *fpq, ccc_destructor_fn *fn)
Clears the fpq calling fn on every element if provided. O(1)-O(N).
void * ccc_fpq_increase(ccc_flat_priority_queue *fpq, void *e, ccc_update_fn *fn, void *aux)
Increase e that is a handle to the stored fpq element. O(lgN).
ccc_threeway_cmp ccc_fpq_order(ccc_flat_priority_queue const *fpq)
Return the order used to initialize the fpq.
ccc_ucount ccc_fpq_size(ccc_flat_priority_queue const *fpq)
Returns the size of the fpq representing active slots.
void * ccc_fpq_front(ccc_flat_priority_queue const *fpq)
Return a pointer to the front (min or max) element in the fpq. O(1).
ccc_result ccc_fpq_alloc(ccc_flat_priority_queue *fpq, size_t new_capacity, ccc_alloc_fn *fn)
Many allocate memory for the fpq.
void * ccc_fpq_decrease(ccc_flat_priority_queue *fpq, void *e, ccc_update_fn *fn, void *aux)
Decrease e that is a handle to the stored fpq element. O(lgN).
void * ccc_fpq_update(ccc_flat_priority_queue *fpq, void *e, ccc_update_fn *fn, void *aux)
Update e that is a handle to the stored fpq element. O(lgN).
struct ccc_fpq_ ccc_flat_priority_queue
A container offering direct storage and sorting of user data by heap order.
Definition: flat_priority_queue.h:36
ccc_result ccc_fpq_heapify(ccc_flat_priority_queue *fpq, void *input_array, size_t input_n, size_t input_elem_size)
Copy input array into the fpq, organizing into heap. O(N).
ccc_result ccc_fpq_pop(ccc_flat_priority_queue *fpq)
Pop the front element (min or max) element in the fpq. O(lgN).
ccc_tribool ccc_fpq_validate(ccc_flat_priority_queue const *fpq)
Verifies the internal invariants of the fpq hold.
ccc_result ccc_fpq_clear_and_free(ccc_flat_priority_queue *fpq, ccc_destructor_fn *fn)
Clears the fpq calling fn on every element if provided and frees the underlying buffer....
ccc_ucount ccc_fpq_capacity(ccc_flat_priority_queue const *fpq)
Returns the capacity of the fpq representing total possible slots.
void * ccc_fpq_push(ccc_flat_priority_queue *fpq, void const *e)
Pushes element pointed to at e into fpq. O(lgN).
ccc_result ccc_fpq_erase(ccc_flat_priority_queue *fpq, void *e)
Erase element e that is a handle to the stored fpq element.
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_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:283
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