1#ifndef CCC_IMPL_DOUBLY_LINKED_LIST_H
2#define CCC_IMPL_DOUBLY_LINKED_LIST_H
14typedef struct ccc_dll_elem_
16 struct ccc_dll_elem_ *n_;
17 struct ccc_dll_elem_ *p_;
23 struct ccc_dll_elem_ sentinel_;
25 size_t dll_elem_offset_;
35void ccc_impl_dll_push_back(
struct ccc_dll_ *,
struct ccc_dll_elem_ *);
37void ccc_impl_dll_push_front(
struct ccc_dll_ *,
struct ccc_dll_elem_ *);
39struct ccc_dll_elem_ *ccc_impl_dll_elem_in(
struct ccc_dll_
const *,
40 void const *user_struct);
45#define ccc_impl_dll_init(dll_name, struct_name, dll_elem_field, cmp_fn, \
48 .sentinel_.n_ = &(dll_name).sentinel_, \
49 .sentinel_.p_ = &(dll_name).sentinel_, \
50 .elem_sz_ = sizeof(struct_name), \
51 .dll_elem_offset_ = offsetof(struct_name, dll_elem_field), \
53 .alloc_ = (alloc_fn), \
59#define ccc_impl_dll_emplace_back(dll_ptr, struct_initializer...) \
61 typeof(struct_initializer) *dll_res_ = NULL; \
62 struct ccc_dll_ *dll_ = (dll_ptr); \
67 dll_res_ = dll_->alloc_(NULL, dll_->elem_sz_, dll_->aux_); \
70 *dll_res_ = (typeof(*dll_res_))struct_initializer; \
71 ccc_impl_dll_push_back( \
72 dll_, ccc_impl_dll_elem_in(dll_, dll_res_)); \
80#define ccc_impl_dll_emplace_front(dll_ptr, struct_initializer...) \
82 typeof(struct_initializer) *dll_res_; \
83 struct ccc_dll_ *dll_ = (dll_ptr); \
84 assert(sizeof(*dll_res_) == dll_->elem_sz_); \
91 dll_res_ = dll_->alloc_(NULL, dll_->elem_sz_, dll_->aux_); \
94 *dll_res_ = struct_initializer; \
95 ccc_impl_dll_push_front(dll_, \
96 ccc_impl_dll_elem_in(dll_, dll_res_)); \
ccc_threeway_cmp ccc_cmp_fn(ccc_cmp)
A callback function for comparing two elements in a container.
Definition: types.h:291
void * ccc_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:283