1#ifndef CCC_IMPL_FLAT_PRIORITY_QUEUE_H
2#define CCC_IMPL_FLAT_PRIORITY_QUEUE_H
25size_t ccc_impl_fpq_bubble_up(
struct ccc_fpq_ *,
char[],
size_t);
27void ccc_impl_fpq_in_place_heapify(
struct ccc_fpq_ *,
size_t n);
29void *ccc_impl_fpq_update_fixup(
struct ccc_fpq_ *,
void *);
34#define ccc_impl_fpq_init(mem_ptr, cmp_order, cmp_fn, alloc_fn, aux_data, \
37 .buf_ = ccc_buf_init(mem_ptr, alloc_fn, aux_data, capacity), \
39 .order_ = (cmp_order), \
43#define ccc_impl_fpq_heapify_init(mem_ptr, cmp_order, cmp_fn, alloc_fn, \
44 aux_data, capacity, size) \
46 __auto_type fpq_heapify_mem_ = (mem_ptr); \
47 struct ccc_fpq_ fpq_heapify_res_ \
48 = ccc_impl_fpq_init(fpq_heapify_mem_, cmp_order, cmp_fn, alloc_fn, \
49 aux_data, capacity); \
50 ccc_impl_fpq_in_place_heapify(&fpq_heapify_res_, (size)); \
57#define ccc_impl_fpq_emplace(fpq, type_initializer...) \
59 typeof(type_initializer) *fpq_res_; \
60 struct ccc_fpq_ *fpq_ = (fpq); \
61 assert(sizeof(*fpq_res_) == ccc_buf_elem_size(&fpq_->buf_).count); \
62 fpq_res_ = ccc_buf_alloc_back(&fpq_->buf_); \
63 if (ccc_buf_size(&fpq_->buf_).count \
64 == ccc_buf_capacity(&fpq_->buf_).count) \
67 ccc_result const extra_space_ = ccc_buf_alloc( \
68 &fpq_->buf_, ccc_buf_capacity(&fpq_->buf_).count * 2, \
70 if (extra_space_ == CCC_RESULT_OK) \
72 fpq_res_ = ccc_buf_back(&fpq_->buf_); \
77 *fpq_res_ = type_initializer; \
78 if (ccc_buf_size(&fpq_->buf_).count > 1) \
80 void *fpq_tmp_ = ccc_buf_at(&fpq_->buf_, \
81 ccc_buf_size(&fpq_->buf_).count); \
82 fpq_res_ = ccc_buf_at( \
84 ccc_impl_fpq_bubble_up( \
85 fpq_, fpq_tmp_, ccc_buf_size(&fpq_->buf_).count - 1)); \
89 fpq_res_ = ccc_buf_at(&fpq_->buf_, 0); \
97#define ccc_impl_fpq_update_w(fpq_ptr, T_ptr, update_closure_over_T...) \
99 struct ccc_fpq_ *const fpq_ = (fpq_ptr); \
100 void *fpq_update_res_ = NULL; \
101 void *const fpq_t_ptr_ = (T_ptr); \
102 if (fpq_ && fpq_t_ptr_ && !ccc_buf_is_empty(&fpq_->buf_)) \
104 {update_closure_over_T} fpq_update_res_ \
105 = ccc_impl_fpq_update_fixup(fpq_, fpq_t_ptr_); \
111#define ccc_impl_fpq_increase_w(fpq_ptr, T_ptr, increase_closure_over_T...) \
112 ccc_impl_fpq_update_w(fpq_ptr, T_ptr, increase_closure_over_T)
115#define ccc_impl_fpq_decrease_w(fpq_ptr, T_ptr, decrease_closure_over_T...) \
116 ccc_impl_fpq_update_w(fpq_ptr, T_ptr, decrease_closure_over_T)
struct ccc_buf_ ccc_buffer
A contiguous block of storage for elements of the same type.
Definition: buffer.h:50
ccc_threeway_cmp ccc_cmp_fn(ccc_cmp)
A callback function for comparing two elements in a container.
Definition: types.h:291
ccc_threeway_cmp
A three-way comparison for comparison functions.
Definition: types.h:138