Go to the source code of this file.
◆ array
The array data structure, which is a static contiguous array.
◆ array_add_all()
bk_err array_add_all |
( |
array |
me, |
|
|
void *const |
arr, |
|
|
const size_t |
size |
|
) |
| |
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.
- Parameters
-
me | the array to add data to |
arr | the raw array to copy data from |
size | the number of elements to copy |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ array_copy_to_array()
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.
- Parameters
-
arr | the initialized raw array to copy the array to |
me | the array to copy to the raw array |
◆ array_destroy()
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.
- Parameters
-
me | the array to free from memory |
- Returns
- NULL
◆ array_get()
bk_err array_get |
( |
void *const |
data, |
|
|
array |
me, |
|
|
const size_t |
index |
|
) |
| |
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.
- Parameters
-
data | the data to copy to |
me | the array to copy from |
index | the index to copy from in the array |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ array_get_data()
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.
- Parameters
-
me | the array to get the storage element from |
- Returns
- the storage element of the array
◆ array_init()
array array_init |
( |
const size_t |
element_count, |
|
|
const size_t |
data_size |
|
) |
| |
Initializes an array.
- Parameters
-
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 |
- Returns
- the newly-initialized array, or NULL if it was not successfully initialized due to either invalid input arguments or memory allocation error
◆ array_set()
bk_err array_set |
( |
array |
me, |
|
|
const size_t |
index, |
|
|
void *const |
data |
|
) |
| |
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.
- Parameters
-
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 |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ array_size()
size_t array_size |
( |
array |
me | ) |
|
Gets the size of the array.
- Parameters
-
- Returns
- the size of the array