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 | |
stack | stack_init (const size_t data_size) |
size_t | stack_size (stack me) |
bk_bool | stack_is_empty (stack me) |
bk_err | stack_trim (stack me) |
void | stack_copy_to_array (void *const arr, stack me) |
bk_err | stack_push (stack me, void *const data) |
bk_bool | stack_pop (void *const data, stack me) |
bk_bool | stack_top (void *const data, stack me) |
bk_err | stack_clear (stack me) |
stack | stack_destroy (stack me) |
Clears the stack and sets it to the state from original initialization.
me | the stack to clear |
void stack_copy_to_array | ( | void *const | arr, |
stack | me | ||
) |
Copies the stack to an array. Since it is a copy, the array may be modified without causing side effects to the stack 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 stack to |
me | the stack to copy to the array |
Frees the stack memory. Performing further operations after calling this function results in undefined behavior. Freeing NULL is legal, and causes no operation to be performed.
me | the stack to destroy |
stack stack_init | ( | const size_t | data_size | ) |
Initializes a stack.
data_size | the size of each data element in the stack; must be positive |
Determines if the stack is empty, meaning it contains no elements.
me | the stack to check if empty |
Removes the top element of the stack, and copies the data which is being removed. The pointer to the data being obtained should point to the data type which this stack holds. For example, if this stack 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 element being removed |
me | the stack to remove the top element from |
Adds an element to the top of the stack. The pointer to the data being passed in should point to the data type which this stack holds. For example, if this stack 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 stack to add an element to |
data | the data to add to the stack |
size_t stack_size | ( | stack | me | ) |
Determines the size of the stack.
me | the stack to check size of |
Copies the top element of the stack. The pointer to the data being obtained should point to the data type which this stack holds. For example, if this stack 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 top element of the stack |
me | the stack to copy from |