O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
internals.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
7/* */
14/* ************************************************************************** */
15
16#include "private.h"
17
18#include "o2s/deque.h"
19
21size_t deque_offset(const deque_t* self, size_t count)
22{
23 return (count * self->type_size);
24}
25
27size_t deque_room(const deque_t* self)
28{
29 return deque_capacity(self) - deque_count(self);
30}
31
33void* deque_begin(const deque_t* self)
34{
35 return self->storage;
36}
37
39void* deque_end(const deque_t* self)
40{
41 return deque_begin(self) + deque_offset(self, deque_capacity(self));
42}
43
45void* deque_pointer_after(const deque_t* self, void* pointer)
46{
47 pointer += deque_offset(self, 1);
48 if (pointer == deque_end(self))
49 pointer = deque_begin(self);
50 return pointer;
51}
52
54void* deque_pointer_before(const deque_t* self, void* pointer)
55{
56 if (pointer == deque_begin(self))
57 pointer = deque_end(self);
58 return pointer - deque_offset(self, 1);
59}
60
62size_t deque_distance(const deque_t* self, const void* one, const void* two)
63{
64 return (one > two ? one - two : two - one) / self->type_size;
65}
size_t deque_capacity(const deque_t *self)
The maximum number of elements that can be stored.
Definition getters.c:28
size_t deque_count(const deque_t *self)
The number of elements currently held in the queue.
Definition getters.c:22
Internal deque state.
Realtime double-ended queues.
size_t deque_distance(const deque_t *self, const void *one, const void *two)
Number of elements in the range delimited by the two provided elements.
Definition internals.c:62
size_t deque_offset(const deque_t *self, size_t count)
The size in memory of count elements.
Definition internals.c:21
void * deque_pointer_before(const deque_t *self, void *pointer)
The previous slot.
Definition internals.c:54
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
void * deque_pointer_after(const deque_t *self, void *pointer)
The next slot.
Definition internals.c:45
size_t deque_room(const deque_t *self)
The remaining number of elements that can be added.
Definition internals.c:27
Double-ended queue.
Definition deque.h:27
size_t type_size
Size in bytes of a single element.
Definition deque.h:33
void * storage
Memory area.
Definition deque.h:28