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 | |
array | array_init (const size_t element_count, const size_t data_size) |
size_t | array_size (array me) |
void | array_copy_to_array (void *const arr, array me) |
void * | array_get_data (array me) |
bk_err | array_add_all (array me, void *const arr, const size_t size) |
bk_err | array_set (array me, const size_t index, void *const data) |
bk_err | array_get (void *const data, array me, const size_t index) |
array | array_destroy (array me) |
Copies elements from a raw array to the array. The size specifies the number of elements to copy starting from the start of the raw array, which must be less than or equal to the size of both the raw array and of the array. The elements are copied to the array starting at the start of the array.
me | the array to add data to |
arr | the raw array to copy data from |
size | the number of elements to copy |
void array_copy_to_array | ( | void *const | arr, |
array | me | ||
) |
Copies the array to a raw array. Since it is a copy, the raw array may be modified without causing side effects to the array data structure. Memory is not allocated, thus the raw array being used for the copy must be allocated before this function is called. The size of the array should be queried prior to calling this function, which also serves as the size of the newly-copied raw array.
arr | the initialized raw array to copy the array to |
me | the array to copy to the raw array |
Frees the array 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 array to free from memory |
Copies the element at an index of the array to data. The pointer to the data being obtained should point to the data type which this array holds. For example, if this array 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 copy to |
me | the array to copy from |
index | the index to copy from in the array |
void* array_get_data | ( | array | me | ) |
Gets the storage element of the array structure. The storage element is contiguous in memory. The data pointer should be assigned to the correct array type. For example, if the array holds integers, the data pointer should be assigned to a raw integer array. The size of the array should be obtained prior to calling this function, which also serves as the size of the queried raw array. This pointer is not a copy, thus any modification to the data will cause the array structure data to be modified. Operations using the array functions may invalidate this pointer. The array owns this memory, thus it should not be freed. If the array size if 0, this should not be used.
me | the array to get the storage element from |
array array_init | ( | const size_t | element_count, |
const size_t | data_size | ||
) |
Initializes an array.
element_count | the number of elements in the array; must not be negative |
data_size | the size of each element in the array; must be positive |
Sets the data for a specified element in the array. The pointer to the data being passed in should point to the data type which this array holds. For example, if this array 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 array to set data for |
index | the location to set data at in the array |
data | the data to set at the location in the array |
size_t array_size | ( | array | me | ) |
Gets the size of the array.
me | the array to check |