C Container Collection (CCC)
Loading...
Searching...
No Matches
flat_double_ended_queue.h
Go to the documentation of this file.
1
26#ifndef CCC_FLAT_DOUBLE_ENDED_QUEUE_H
27#define CCC_FLAT_DOUBLE_ENDED_QUEUE_H
28
30#include <stddef.h>
33#include "impl/impl_flat_double_ended_queue.h"
34#include "types.h"
35
46typedef struct ccc_fdeq_ ccc_flat_double_ended_queue;
47
62#define ccc_fdeq_init(mem_ptr, alloc_fn, aux_data, capacity, optional_size...) \
63 ccc_impl_fdeq_init(mem_ptr, alloc_fn, aux_data, capacity, optional_size)
64
126 ccc_alloc_fn *fn);
127
142#define ccc_fdeq_emplace_back(fdeq_ptr, value...) \
143 ccc_impl_fdeq_emplace_back(fdeq_ptr, value)
144
153#define ccc_fdeq_emplace_front(fdeq_ptr, value...) \
154 ccc_impl_fdeq_emplace_front(fdeq_ptr, value)
155
163 void const *elem);
164
177 void const *elems);
178
186 void const *elem);
187
200 size_t n, void const *elems);
201
240 void *pos, size_t n,
241 void const *elems);
242
248
254
270 ccc_destructor_fn *destructor);
271
282 ccc_destructor_fn *destructor);
283
293[[nodiscard]] void *ccc_fdeq_begin(ccc_flat_double_ended_queue const *fdeq);
294
298[[nodiscard]] void *ccc_fdeq_rbegin(ccc_flat_double_ended_queue const *fdeq);
299
304[[nodiscard]] void *ccc_fdeq_next(ccc_flat_double_ended_queue const *fdeq,
305 void const *iter_ptr);
306
311[[nodiscard]] void *ccc_fdeq_rnext(ccc_flat_double_ended_queue const *fdeq,
312 void const *iter_ptr);
313
317[[nodiscard]] void *ccc_fdeq_end(ccc_flat_double_ended_queue const *fdeq);
318
322[[nodiscard]] void *ccc_fdeq_rend(ccc_flat_double_ended_queue const *fdeq);
323
337[[nodiscard]] void *ccc_fdeq_at(ccc_flat_double_ended_queue const *fdeq,
338 size_t i);
339
344[[nodiscard]] void *ccc_fdeq_front(ccc_flat_double_ended_queue const *fdeq);
345
350[[nodiscard]] void *ccc_fdeq_back(ccc_flat_double_ended_queue const *fdeq);
351
355[[nodiscard]] bool ccc_fdeq_is_empty(ccc_flat_double_ended_queue const *fdeq);
356
360[[nodiscard]] size_t ccc_fdeq_size(ccc_flat_double_ended_queue const *fdeq);
361
365[[nodiscard]] size_t ccc_fdeq_capacity(ccc_flat_double_ended_queue const *fdeq);
366
377[[nodiscard]] void *ccc_fdeq_data(ccc_flat_double_ended_queue const *fdeq);
378
382[[nodiscard]] bool ccc_fdeq_validate(ccc_flat_double_ended_queue const *fdeq);
383
388#ifdef FLAT_DOUBLE_ENDED_QUEUE_USING_NAMESPACE_CCC
389typedef ccc_flat_double_ended_queue flat_double_ended_queue;
390# define fdeq_init(args...) ccc_fdeq_init(args)
391# define fdeq_copy(args...) ccc_fdeq_copy(args)
392# define fdeq_emplace(args...) ccc_fdeq_emplace(args)
393# define fdeq_push_back(args...) ccc_fdeq_push_back(args)
394# define fdeq_push_back_range(args...) ccc_fdeq_push_back_range(args)
395# define fdeq_push_front(args...) ccc_fdeq_push_front(args)
396# define fdeq_push_front_range(args...) ccc_fdeq_push_front_range(args)
397# define fdeq_insert_range(args...) ccc_fdeq_insert_range(args)
398# define fdeq_pop_front(args...) ccc_fdeq_pop_front(args)
399# define fdeq_pop_back(args...) ccc_fdeq_pop_back(args)
400# define fdeq_front(args...) ccc_fdeq_front(args)
401# define fdeq_back(args...) ccc_fdeq_back(args)
402# define fdeq_is_empty(args...) ccc_fdeq_is_empty(args)
403# define fdeq_size(args...) ccc_fdeq_size(args)
404# define fdeq_clear(args...) ccc_fdeq_clear(args)
405# define fdeq_clear_and_free(args...) ccc_fdeq_clear_and_free(args)
406# define fdeq_at(args...) ccc_fdeq_at(args)
407# define fdeq_data(args...) ccc_fdeq_data(args)
408# define fdeq_begin(args...) ccc_fdeq_begin(args)
409# define fdeq_rbegin(args...) ccc_fdeq_rbegin(args)
410# define fdeq_next(args...) ccc_fdeq_next(args)
411# define fdeq_rnext(args...) ccc_fdeq_rnext(args)
412# define fdeq_end(args...) ccc_fdeq_end(args)
413# define fdeq_rend(args...) ccc_fdeq_rend(args)
414# define fdeq_validate(args...) ccc_fdeq_validate(args)
415#endif /* FLAT_DOUBLE_ENDED_QUEUE_USING_NAMESPACE_CCC */
416
417#endif /* CCC_FLAT_DOUBLE_ENDED_QUEUE_H */
void * ccc_fdeq_rbegin(ccc_flat_double_ended_queue const *fdeq)
Return a pointer to the back element of the fdeq. O(1).
struct ccc_fdeq_ ccc_flat_double_ended_queue
A contiguous buffer for O(1) push and pop from front and back.
Definition: flat_double_ended_queue.h:46
size_t ccc_fdeq_size(ccc_flat_double_ended_queue const *fdeq)
Return the size of the fdeq. O(1).
ccc_result ccc_fdeq_clear(ccc_flat_double_ended_queue *fdeq, ccc_destructor_fn *destructor)
Set size of fdeq to 0 and call destructor on each element if needed. O(1) if no destructor is provide...
void * ccc_fdeq_next(ccc_flat_double_ended_queue const *fdeq, void const *iter_ptr)
Return the next element in the fdeq moving front to back. O(1).
ccc_result ccc_fdeq_push_back_range(ccc_flat_double_ended_queue *fdeq, size_t n, void const *elems)
Push the range of user types to the back of the fdeq. O(N).
void * ccc_fdeq_insert_range(ccc_flat_double_ended_queue *fdeq, void *pos, size_t n, void const *elems)
Push the range of user types before pos of the fdeq. O(N).
bool ccc_fdeq_validate(ccc_flat_double_ended_queue const *fdeq)
Return true if the internal invariants of the fdeq.
void * ccc_fdeq_at(ccc_flat_double_ended_queue const *fdeq, size_t i)
Return a reference to the element at index position i. O(1).
ccc_result ccc_fdeq_push_front_range(ccc_flat_double_ended_queue *fdeq, size_t n, void const *elems)
Push the range of user types to the front of the fdeq. O(N).
ccc_result ccc_fdeq_pop_back(ccc_flat_double_ended_queue *fdeq)
Pop an element from the back of the fdeq. O(1).
ccc_result ccc_fdeq_clear_and_free(ccc_flat_double_ended_queue *fdeq, ccc_destructor_fn *destructor)
Set size of fdeq to 0 and call destructor on each element if needed. Free the underlying buffer setti...
void * ccc_fdeq_push_front(ccc_flat_double_ended_queue *fdeq, void const *elem)
Push the user type to the front of the fdeq. O(1) if no allocation permission amortized O(1) if alloc...
ccc_result ccc_fdeq_copy(ccc_flat_double_ended_queue *dst, ccc_flat_double_ended_queue const *src, ccc_alloc_fn *fn)
Copy the fdeq from src to newly initialized dst.
bool ccc_fdeq_is_empty(ccc_flat_double_ended_queue const *fdeq)
Return true if the size of the fdeq is 0. O(1).
void * ccc_fdeq_front(ccc_flat_double_ended_queue const *fdeq)
Return a reference to the front of the fdeq. O(1).
void * ccc_fdeq_rend(ccc_flat_double_ended_queue const *fdeq)
Return a pointer to the start element. It may not be accessed. O(1).
void * ccc_fdeq_end(ccc_flat_double_ended_queue const *fdeq)
Return a pointer to the end element. It may not be accessed. O(1).
void * ccc_fdeq_back(ccc_flat_double_ended_queue const *fdeq)
Return a reference to the back of the fdeq. O(1).
void * ccc_fdeq_push_back(ccc_flat_double_ended_queue *fdeq, void const *elem)
Push the user type to the back of the fdeq. O(1) if no allocation permission amortized O(1) if alloca...
void * ccc_fdeq_data(ccc_flat_double_ended_queue const *fdeq)
Return a reference to the base of backing array. O(1).
void * ccc_fdeq_begin(ccc_flat_double_ended_queue const *fdeq)
Return a pointer to the front element of the fdeq. O(1).
size_t ccc_fdeq_capacity(ccc_flat_double_ended_queue const *fdeq)
Return the capacity of the fdeq. O(1).
ccc_result ccc_fdeq_pop_front(ccc_flat_double_ended_queue *fdeq)
Pop an element from the front of the fdeq. O(1).
void * ccc_fdeq_rnext(ccc_flat_double_ended_queue const *fdeq, void const *iter_ptr)
Return the next element in the fdeq moving back to front. O(1).
The C Container Collection Fundamental Types.
ccc_result
A result of actions on containers.
Definition: types.h:65
void * ccc_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:199
void ccc_destructor_fn(ccc_user_type)
A callback function for destroying an element in the container.
Definition: types.h:234