43#define DequeNew(Storage, Capacity, Type) \
44 deque_new(Storage, Capacity, sizeof(Type))
54#define DequeAllocate(Capacity, Type) deque_allocate(Capacity, sizeof(Type))
71#define Deque __attribute__((cleanup(deque_free))) deque_t
123#define deque_foreach(TYPE, DEQUE, ELEMENT) \
124 for (unsigned _i = 0; _i < deque_count(DEQUE) \
125 && ((*(ELEMENT) = *(TYPE*)deque_get(DEQUE, _i)) || true); \
132#define deque_enumerate(TYPE, DEQUE, ELEMENT, INDEX) \
133 for (*(INDEX) = 0; *(INDEX) < deque_count(DEQUE) \
134 && ((*(ELEMENT) = *(TYPE*)deque_get(DEQUE, *(INDEX))) || true); \
void deque_free(deque_t *self)
Frees properly the deque.
void * deque_last(const deque_t *self)
The current last element in the queue.
bool deque_push_front(deque_t *self, const void *element)
Inserts an element to the front of the queue.
bool deque_pop_back(deque_t *self, void *destination)
Pops the last element in the queue.
size_t deque_capacity(const deque_t *self)
The maximum number of elements that can be stored.
bool deque_push_back(deque_t *self, const void *element)
Inserts an element to the back of the queue.
bool deque_pop_front_into_array(deque_t *self, struct array *destination, size_t count)
Move the count first elements at the back of destination.
bool deque_push_front_n(deque_t *self, const void *elements, size_t count)
Inserts count elements to the front of the queue.
void deque_clear(deque_t *self)
Clears properly the deque.
void * deque_first(const deque_t *self)
The current first element in the queue.
bool deque_is_empty(const deque_t *self)
True if no elements are currently stored.
deque_t deque_new(void *storage, size_t capacity, size_t type_size)
Contructs an deque, using externally owned memory.
size_t deque_count(const deque_t *self)
The number of elements currently held in the queue.
bool deque_pop_back_n(deque_t *self, void *destination, size_t count)
Pops the count last elements in the queue.
void deque_reserve(deque_t *self, size_t count)
Reallocates the deque if count elements cannot fit in the current allocation.
bool deque_push_back_n(deque_t *self, const void *elements, size_t count)
Inserts count elements to the back of the queue.
bool deque_pop_front(deque_t *self, void *destination)
Pops the front-most element of the queue, copying it to destination.
bool deque_pop_front_n(deque_t *self, void *destination, size_t count)
Pops the count first elements of the queue.
bool deque_is_full(const deque_t *self)
True if the queue reached its maximum capacity.
deque_t deque_allocate(size_t capacity, size_t type_size)
Constructs a deque, allocating the needed memory.
size_t deque_room(const deque_t *self)
The remaining number of elements that can be added.
void * deque_get(const deque_t *self, size_t index)
The element of the element at an arbitrary index.
size_t type_size
Size in bytes of a single element.
void * back
Pointer past-the-end of the queue.
void * front
Pointer to the front of the queue.
size_t capacity
Maximum number of elements that can be stored.
size_t count
Number of elements currently stored.
void * storage
Memory area.