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/array.h"
20
25void* array_end(const array_t* self)
26{
27 if (self->capacity == 0)
28 return NULL;
29 return (self->start + array_offset(self, self->count));
30}
31
36void* array_first(const array_t* self)
37{
38 return array_get(self, 0);
39}
40
45void* array_last(const array_t* self)
46{
47 if (array_is_empty(self))
48 return NULL;
49 return array_get(self, self->count - 1);
50}
51
56void* array_get(const array_t* self, size_t index)
57{
58 if (index >= self->count)
59 return NULL;
60 return self->start + array_offset(self, index);
61}
62
64bool array_is_empty(const array_t* self)
65{
66 return self->count == 0;
67}
68
70size_t array_count(const array_t* self)
71{
72 return self->count;
73}
void * array_first(const array_t *self)
Pointer to the first element of the array.
Definition getters.c:36
bool array_is_empty(const array_t *self)
True if the array contains no element.
Definition getters.c:64
void * array_last(const array_t *self)
Pointer of the last element of the array.
Definition getters.c:45
void * array_end(const array_t *self)
One-past-the-end pointer of the array.
Definition getters.c:25
void * array_get(const array_t *self, size_t index)
Pointer of the element at position index of the array.
Definition getters.c:56
size_t array_count(const array_t *self)
Number of elements stored.
Definition getters.c:70
Internal state of a dynamic array.
Dynamic arrays.
size_t array_offset(const array_t *self, size_t count)
The size in memory of count elements.
Definition memory.c:23
O2S array implementation.
Definition array.h:24
void * start
Underlying storage.
Definition array.h:25
size_t count
Number of elements currently stored.
Definition array.h:27
size_t capacity
Number of elements that can fit in the storage.
Definition array.h:28