Containers
This library provides various containers. Each container has utility functions to manipulate the data it holds. This is an abstraction as to not have to manually manage and reallocate memory.
|
Functions | |
queue | queue_init (const size_t data_size) |
size_t | queue_size (queue me) |
bk_bool | queue_is_empty (queue me) |
bk_err | queue_trim (queue me) |
void | queue_copy_to_array (void *const arr, queue me) |
bk_err | queue_push (queue me, void *const data) |
bk_bool | queue_pop (void *const data, queue me) |
bk_bool | queue_front (void *const data, queue me) |
bk_bool | queue_back (void *const data, queue me) |
bk_err | queue_clear (queue me) |
queue | queue_destroy (queue me) |
Gets the back element of the queue. The pointer to the data being obtained should point to the data type which this queue holds. For example, if this queue holds integers, the data pointer should be a pointer to an integer. Since this data is being copied from the array to the data pointer, the pointer only has to be valid when this function is called.
data | the copy of the back element of the queue |
me | the queue to copy from |
Clears the queue and sets it to the original state from initialization.
me | the queue to clear |
void queue_copy_to_array | ( | void *const | arr, |
queue | me | ||
) |
Copies the queue to an array. Since it is a copy, the array may be modified without causing side effects to the queue data structure. Memory is not allocated, thus the array being used for the copy must be allocated before this function is called.
arr | the initialized array to copy the queue to |
me | the queue to copy to the array |
Destroys the queue. Performing further operations after calling this function results in undefined behavior. Freeing NULL is legal, and causes no operation to be performed.
me | the queue to destroy |
Gets the front element of the queue. The pointer to the data being obtained should point to the data type which this queue holds. For example, if this queue holds integers, the data pointer should be a pointer to an integer. Since this data is being copied from the array to the data pointer, the pointer only has to be valid when this function is called.
data | the copy of the front element of the queue |
me | the queue to copy from |
queue queue_init | ( | const size_t | data_size | ) |
Initializes a queue.
data_size | the size of each element; must be positive |
Determines if the queue is empty. The queue is empty if it contains no elements.
me | the queue to check if empty |
Removes the next element in the queue and copies the data. The pointer to the data being obtained should point to the data type which this queue holds. For example, if this queue holds integers, the data pointer should be a pointer to an integer. Since this data is being copied from the array to the data pointer, the pointer only has to be valid when this function is called.
data | the data to have copied from the queue |
me | the queue to pop the next element from |
Adds an element to the queue. The pointer to the data being passed in should point to the data type which this queue holds. For example, if this queue holds integers, the data pointer should be a pointer to an integer. Since the data is being copied, the pointer only has to be valid when this function is called.
me | the queue to add an element to |
data | the data to add to the queue |
size_t queue_size | ( | queue | me | ) |
Determines the size of the queue.
me | the queue to get size of |