O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
getters.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
7/* */
15/* ************************************************************************** */
16
17#include "private.h"
18
19#include "o2s/deque.h"
20
22size_t deque_count(const deque_t* self)
23{
24 return self->count;
25}
26
28size_t deque_capacity(const deque_t* self)
29{
30 return self->capacity;
31}
32
37void* deque_first(const deque_t* self)
38{
39 if (deque_is_empty(self))
40 return NULL;
41 return self->front;
42}
43
48void* deque_last(const deque_t* self)
49{
50 if (deque_is_empty(self))
51 return NULL;
52 return (self->back == deque_begin(self) ? deque_end(self) : self->back)
53 - deque_offset(self, 1);
54}
55
57bool deque_is_empty(const deque_t* self)
58{
59 return deque_count(self) == 0;
60}
61
63bool deque_is_full(const deque_t* self)
64{
65 return deque_count(self) == deque_capacity(self);
66}
67
72void* deque_get(const deque_t* self, size_t index)
73{
74 if (index >= deque_count(self))
75 return NULL;
76 void* result = self->front + deque_offset(self, index);
77 if (result >= deque_end(self))
78 result -= deque_offset(self, deque_capacity(self));
79 return result;
80}
void * deque_last(const deque_t *self)
The current last element in the queue.
Definition getters.c:48
size_t deque_capacity(const deque_t *self)
The maximum number of elements that can be stored.
Definition getters.c:28
void * deque_first(const deque_t *self)
The current first element in the queue.
Definition getters.c:37
bool deque_is_empty(const deque_t *self)
True if no elements are currently stored.
Definition getters.c:57
size_t deque_count(const deque_t *self)
The number of elements currently held in the queue.
Definition getters.c:22
bool deque_is_full(const deque_t *self)
True if the queue reached its maximum capacity.
Definition getters.c:63
void * deque_get(const deque_t *self, size_t index)
The element of the element at an arbitrary index.
Definition getters.c:72
Internal deque state.
Realtime double-ended queues.
size_t deque_offset(const deque_t *self, size_t count)
The size in memory of count elements.
Definition internals.c:21
void * deque_begin(const deque_t *self)
Pointer to the start of the underlying storage.
Definition internals.c:33
void * deque_end(const deque_t *self)
Pointer one-past-the-end of the underlying storage.
Definition internals.c:39
Double-ended queue.
Definition deque.h:27
void * back
Pointer past-the-end of the queue.
Definition deque.h:30
void * front
Pointer to the front of the queue.
Definition deque.h:29
size_t capacity
Maximum number of elements that can be stored.
Definition deque.h:32
size_t count
Number of elements currently stored.
Definition deque.h:31