C Container Collection (CCC)
Loading...
Searching...
No Matches
impl_flat_double_ended_queue.h
1#ifndef CCC_IMPL_FLAT_DOUBLE_ENDED_QUEUE_H
2#define CCC_IMPL_FLAT_DOUBLE_ENDED_QUEUE_H
3
5#include <stddef.h>
8#include "../buffer.h"
9
10/* NOLINTBEGIN(readability-identifier-naming) */
11
13struct ccc_fdeq_
14{
15 ccc_buffer buf_;
16 size_t front_;
17};
18
19/*======================= Private Interface ============================*/
21void *ccc_impl_fdeq_alloc_front(struct ccc_fdeq_ *);
23void *ccc_impl_fdeq_alloc_back(struct ccc_fdeq_ *);
24
25/*======================= Macro Implementations ==========================*/
26
28#define ccc_impl_fdeq_init(mem_ptr, alloc_fn, aux_data, capacity, \
29 optional_size...) \
30 { \
31 .buf_ \
32 = ccc_buf_init(mem_ptr, alloc_fn, aux_data, capacity, optional_size), \
33 .front_ = 0, \
34 }
35
37#define ccc_impl_fdeq_emplace_back(fdeq_ptr, value...) \
38 (__extension__({ \
39 __auto_type fdeq_ptr_ = (fdeq_ptr); \
40 void *const fdeq_emplace_ret_ = NULL; \
41 if (fdeq_ptr_) \
42 { \
43 void *const fdeq_emplace_ret_ \
44 = ccc_impl_fdeq_alloc_back(fdeq_ptr_); \
45 if (fdeq_emplace_ret_) \
46 { \
47 *((typeof(value) *)fdeq_emplace_ret_) = value; \
48 } \
49 } \
50 fdeq_emplace_ret_; \
51 }))
52
54#define ccc_impl_fdeq_emplace_front(fdeq_ptr, value...) \
55 (__extension__({ \
56 __auto_type fdeq_ptr_ = (fdeq_ptr); \
57 void *const fdeq_emplace_ret_ = NULL; \
58 if (fdeq_ptr_) \
59 { \
60 void *const fdeq_emplace_ret_ \
61 = ccc_impl_fdeq_alloc_front(fdeq_ptr_); \
62 if (fdeq_emplace_ret_) \
63 { \
64 *((typeof(value) *)fdeq_emplace_ret_) = value; \
65 } \
66 } \
67 fdeq_emplace_ret_; \
68 }))
69
70/* NOLINTEND(readability-identifier-naming) */
71
72#endif /* CCC_IMPL_FLAT_DOUBLE_ENDED_QUEUE_H */
struct ccc_buf_ ccc_buffer
A contiguous block of storage for elements of the same type.
Definition: buffer.h:50