C Container Collection (CCC)
Loading...
Searching...
No Matches
impl_singly_linked_list.h
1
#ifndef CCC_IMPL_SINGLY_LINKED_LIST_H
2
#define CCC_IMPL_SINGLY_LINKED_LIST_H
3
5
#include <assert.h>
6
#include <stddef.h>
9
#include "../types.h"
10
11
/* NOLINTBEGIN(readability-identifier-naming) */
12
14
typedef
struct
ccc_sll_elem_
15
{
16
struct
ccc_sll_elem_ *n_;
17
} ccc_sll_elem_;
18
20
struct
ccc_sll_
21
{
22
struct
ccc_sll_elem_ sentinel_;
23
size_t
sz_;
24
size_t
elem_sz_;
25
size_t
sll_elem_offset_;
26
ccc_alloc_fn
*alloc_;
27
ccc_cmp_fn
*cmp_;
28
void
*aux_;
29
};
30
31
/*========================= Private Interface ============================*/
32
34
void
ccc_impl_sll_push_front(
struct
ccc_sll_ *,
struct
ccc_sll_elem_ *);
35
36
/*====================== Macro Implementations ========================*/
37
39
#define ccc_impl_sll_init(sll_name, struct_name, sll_elem_field, cmp_fn, \
40
alloc_fn, aux_data) \
41
{ \
42
.sentinel_.n_ = &(sll_name).sentinel_, \
43
.elem_sz_ = sizeof(struct_name), \
44
.sll_elem_offset_ = offsetof(struct_name, sll_elem_field), \
45
.sz_ = 0, \
46
.alloc_ = (alloc_fn), \
47
.cmp_ = (cmp_fn), \
48
.aux_ = (aux_data), \
49
}
50
52
#define ccc_impl_sll_emplace_front(list_ptr, struct_initializer...) \
53
(__extension__({ \
54
typeof(struct_initializer) *sll_res_ = NULL; \
55
struct ccc_sll_ *sll_ = (list_ptr); \
56
if (sll_) \
57
{ \
58
if (!sll_->alloc_) \
59
{ \
60
sll_res_ = NULL; \
61
} \
62
else \
63
{ \
64
sll_res_ = sll_->alloc_(NULL, sll_->elem_sz_); \
65
if (sll_res_) \
66
{ \
67
*sll_res_ = struct_initializer; \
68
ccc_impl_sll_push_front(sll_, \
69
ccc_sll_elem_in(sll_, sll_res_)); \
70
} \
71
} \
72
} \
73
sll_res_; \
74
}))
75
76
/* NOLINTEND(readability-identifier-naming) */
77
78
#endif
/* CCC_IMPL_SINGLY_LINKED_LIST_H */
ccc_cmp_fn
ccc_threeway_cmp ccc_cmp_fn(ccc_cmp)
A callback function for comparing two elements in a container.
Definition:
types.h:291
ccc_alloc_fn
void * ccc_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition:
types.h:283
ccc
impl
impl_singly_linked_list.h
Generated by
1.9.6