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.
array.h File Reference
#include "_bk_defines.h"
Include dependency graph for array.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef char * array
 

Functions

array array_init (size_t element_count, size_t data_size)
 
size_t array_size (array me)
 
void array_copy_to_array (void *arr, array me)
 
void * array_get_data (array me)
 
bk_err array_add_all (array me, void *arr, size_t size)
 
bk_err array_set (array me, size_t index, void *data)
 
bk_err array_get (void *data, array me, size_t index)
 
array array_destroy (array me)
 

Typedef Documentation

◆ array

typedef char* array

The array data structure, which is a static contiguous array.

Function Documentation

◆ 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
methe array to add data to
arrthe raw array to copy data from
sizethe 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
arrthe initialized raw array to copy the array to
methe array to copy to the raw array

◆ array_destroy()

array array_destroy ( array  me)

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
methe 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
datathe data to copy to
methe array to copy from
indexthe 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
methe 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_countthe number of elements in the array; must not be negative
data_sizethe 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
methe array to set data for
indexthe location to set data at in the array
datathe 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
methe array to check
Returns
the size of the array