lib<g2l> 0.1.0
A simple and experimental C implementation of a generic doubly linked list
|
Go to the source code of this file.
Typedefs | |
typedef struct g2l_t | g2l_t |
Functions | |
g2l_t * | g2l_create (size_t data_size, bool abort_on_enomem) |
void | g2l_clear (g2l_t *self) |
void | g2l_destroy (g2l_t *self) |
size_t | g2l_size (g2l_t const *self) |
int | g2l_push (g2l_t *self, void const *data) |
bool | g2l_pop (g2l_t *self, void *data) |
bool | g2l_shift (g2l_t *self, void *data) |
bool | g2l_enqueue (g2l_t *self, void const *data) |
bool | g2l_dequeue (g2l_t *self, void *data) |
An opaque data type used as a container for the generic doubly linked list implementation, and which must be instantiated using the g2l_create function.
A function that can be used to clear (i.e., empty) a linked list object.
self | A pointer to the g2l_t instance to be cleared. |
The function that must be used to instantiate a new linked list object (i.e., g2l_t ).
data_size | The size, in bytes, of the data type that will be stored in the created instance. |
abort_on_enomem | Whether ENOMEM errors should result in the process being aborted (true ) or whether the function should simply return the NULL pointer and let the application deal with the error. |
abort_on_enomem
is set to false
and an error occurs, that error will be due to an internal call to malloc failing, in which case errno will contain ENOMEM , which will have been set by malloc . abort_on_enomem
to false
will also require the application to inspect the value returned by g2l_push (and its g2l_enqueue alias), which function also internally makes use of malloc , and which could consequently obtain ENOMEM . An alias to g2l_shift , this function can be used to "dequeue" (i.e., shift) the list's oldest element (and optionally retrieve the value contained in that element).
self | A pointer to the g2l_t instance for which to remove the oldest element. |
data | A pointer to memory into which the list's oldest element's data should be copied before the element is freed. The NULL pointer can be passed if the data is not needed by the application. |
false
value simply means that the list was already empty at the moment when the operation was performed, else the value will be true
. The function that should be used to destroy a linked list object once it is no longer needed by the application.
self | A pointer to the g2l_t instance to be destroyed. |
An alias to g2l_push , a function that can be used to "enqueue" a new element to the linked list object self
.
self | A pointer to the g2l_t instance into which to enqueue (i.e., push) the new element. |
data | A pointer to arbitrary memory of size defined when instantiating the object using g2l_create , which is to be copied and stored inside the linked list object self . |
0
if the new element was successfully added, else it will be ENOMEM . The function that must be used to "pop" the stack (and optionally retrieve the value contained in the list's top-most (i.e., youngest) element).
self | A pointer to the g2l_t instance for which to remove the top-most (i.e., youngest) element. |
data | A pointer to memory into which the list's top-most element's data should be copied before the element is freed. The NULL pointer can be passed if the data is not needed by the application. |
false
value simply means that the list was already empty at the moment when the operation was performed, else the value will be true
. The function that must be used to add a new element to the linked list object self
.
self | A pointer to the g2l_t instance into which to push the new element. |
data | A pointer to arbitrary memory of size defined when instantiating the object using g2l_create , which is to be copied and stored inside the linked list object self . |
0
if the new element was successfully added, else it will be ENOMEM . self
has been instantiated with g2l_create 's abort_on_enomem
argument set to true
, then this function will always return 0
, because possible ENOMEM errors obtained using malloc will result in the process being aborted. Therefore, in such cases (i.e., when setting abort_on_enomem = true
), the output of the g2l_push should simply be ignored. The function that must be used to "shift" the list's oldest element (and optionally retrieve the value contained in that element).
self | A pointer to the g2l_t instance for which to remove the oldest element. |
data | A pointer to memory into which the list's oldest element's data should be copied before the element is freed. The NULL pointer can be passed if the data is not needed by the application. |
false
value simply means that the list was already empty at the moment when the operation was performed, else the value will be true
.