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.
|
Macros | |
#define | BKTHOMPS_DEQUE_MAX_BLOCK_BYTE_SIZE 4096 |
#define | BKTHOMPS_DEQUE_MIN_BLOCK_ELEMENT_SIZE 16 |
#define | BKTHOMPS_DEQUE_INITIAL_BLOCK_COUNT 8 |
#define | BKTHOMPS_DEQUE_RESIZE_RATIO 1.5 |
Functions | |
deque | deque_init (const size_t data_size) |
size_t | deque_size (deque me) |
bk_bool | deque_is_empty (deque me) |
bk_err | deque_trim (deque me) |
void | deque_copy_to_array (void *const arr, deque me) |
bk_err | deque_add_all (deque me, void *const arr, const size_t size) |
bk_err | deque_push_front (deque me, void *const data) |
bk_err | deque_push_back (deque me, void *const data) |
bk_err | deque_pop_front (void *const data, deque me) |
bk_err | deque_pop_back (void *const data, deque me) |
bk_err | deque_set_first (deque me, void *const data) |
bk_err | deque_set_at (deque me, size_t index, void *const data) |
bk_err | deque_set_last (deque me, void *const data) |
bk_err | deque_get_first (void *const data, deque me) |
bk_err | deque_get_at (void *const data, deque me, size_t index) |
bk_err | deque_get_last (void *const data, deque me) |
bk_err | deque_clear (deque me) |
deque | deque_destroy (deque me) |
#define BKTHOMPS_DEQUE_INITIAL_BLOCK_COUNT 8 |
#define BKTHOMPS_DEQUE_MAX_BLOCK_BYTE_SIZE 4096 |
#define BKTHOMPS_DEQUE_MIN_BLOCK_ELEMENT_SIZE 16 |
#define BKTHOMPS_DEQUE_RESIZE_RATIO 1.5 |
Copies elements from an array to the deque. The size specifies the number of elements to copy, starting from the beginning of the array. The size must be less than or equal to the size of the array.
me | the deque to add data to |
arr | the array to copy data from |
size | the number of elements to copy |
Clears the deque and sets it to the original state from initialization.
me | the deque to clear |
void deque_copy_to_array | ( | void *const | arr, |
deque | me | ||
) |
Copies the deque to an array. Since it is a copy, the array may be modified without causing side effects to the deque data structure. Memory is not allocated, thus the array being used for the copy must be allocated before this function is called. The size of the deque should be queried prior to calling this function, which also serves as the size of the newly-copied array.
arr | the initialized array to copy the deque to |
me | the deque to copy to the array |
Destroys the deque. Performing further operations after calling this function results in undefined behavior. Freeing NULL is legal, and causes no operation to be performed.
me | the deque to destroy |
Gets the value of the deque at the specified index. The pointer to the data being obtained should point to the data type which this deque holds. For example, if this deque 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 set |
me | the deque to set the value of |
index | the index to set at |
Gets the first value of the deque. The pointer to the data being obtained should point to the data type which this deque holds. For example, if this deque 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 set |
me | the deque to set the value of |
Gets the last value of the deque. The pointer to the data being obtained should point to the data type which this deque holds. For example, if this deque 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 set |
me | the deque to set the value of |
deque deque_init | ( | const size_t | data_size | ) |
Initializes a deque.
data_size | the size of each element in the deque; must be positive |
Determines if the deque is empty. It is empty if it has no elements.
me | the deque to check if empty |
Removes the back element from the deque and copies it to a data value. The pointer to the data being obtained should point to the data type which this deque holds. For example, if this deque 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 value to copy to |
me | the deque to remove from |
Removes the front element from the deque and copies it to a data value. The pointer to the data being obtained should point to the data type which this deque holds. For example, if this deque 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 value to copy to |
me | the deque to remove from |
Adds an element to the back of the deque. The pointer to the data being passed in should point to the data type which this deque holds. For example, if this deque 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 deque to add an element to |
data | the element to add |
Adds an element to the front of the deque. The pointer to the data being passed in should point to the data type which this deque holds. For example, if this deque 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 deque to add an element to |
data | the element to add |
Sets the value of the deque at the specified index. The pointer to the data being passed in should point to the data type which this deque holds. For example, if this deque 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 deque to set the value of |
index | the index to set at |
data | the data to set |
Sets the first value of the deque. The pointer to the data being passed in should point to the data type which this deque holds. For example, if this deque 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 deque to set the value of |
data | the data to set |
Sets the last value of the deque. The pointer to the data being passed in should point to the data type which this deque holds. For example, if this deque 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 deque to set the value of |
data | the data to set |
size_t deque_size | ( | deque | me | ) |
Determines the size of the deque. The size is the number of data spaces being used. The size starts at zero, and every time an element is added, it increases by one.
me | the deque to check the size of |