Go to the source code of this file.
|
typedef struct internal_vector * | vector |
|
|
vector | vector_init (size_t data_size) |
|
size_t | vector_size (vector me) |
|
size_t | vector_capacity (vector me) |
|
bk_bool | vector_is_empty (vector me) |
|
bk_err | vector_reserve (vector me, size_t size) |
|
bk_err | vector_trim (vector me) |
|
void | vector_copy_to_array (void *arr, vector me) |
|
void * | vector_get_data (vector me) |
|
bk_err | vector_add_all (vector me, void *arr, size_t size) |
|
bk_err | vector_add_first (vector me, void *data) |
|
bk_err | vector_add_at (vector me, size_t index, void *data) |
|
bk_err | vector_add_last (vector me, void *data) |
|
bk_err | vector_remove_first (vector me) |
|
bk_err | vector_remove_at (vector me, size_t index) |
|
bk_err | vector_remove_last (vector me) |
|
bk_err | vector_set_first (vector me, void *data) |
|
bk_err | vector_set_at (vector me, size_t index, void *data) |
|
bk_err | vector_set_last (vector me, void *data) |
|
bk_err | vector_get_first (void *data, vector me) |
|
bk_err | vector_get_at (void *data, vector me, size_t index) |
|
bk_err | vector_get_last (void *data, vector me) |
|
bk_err | vector_clear (vector me) |
|
vector | vector_destroy (vector me) |
|
◆ vector
typedef struct internal_vector* vector |
The vector data structure, which is a dynamic contiguous array.
◆ vector_add_all()
bk_err vector_add_all |
( |
vector |
me, |
|
|
void *const |
arr, |
|
|
const size_t |
size |
|
) |
| |
Copies elements from an array to the vector. 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.
- Parameters
-
me | the vector to add data to |
arr | the array to copy data from |
size | the number of elements to copy |
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory
-
-BK_ERANGE if size has reached representable limit
◆ vector_add_at()
bk_err vector_add_at |
( |
vector |
me, |
|
|
const size_t |
index, |
|
|
void *const |
data |
|
) |
| |
Adds an element to the location specified. The pointer to the data being passed in should point to the data type which this vector holds. For example, if this vector 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 vector to add to |
index | the location in the vector to add the data to |
data | the data to add to the vector |
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory
-
-BK_EINVAL if invalid argument
-
-BK_ERANGE if size has reached representable limit
◆ vector_add_first()
Adds an element to the start of the vector. The pointer to the data being passed in should point to the data type which this vector holds. For example, if this vector 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 vector to add to |
data | the data to add to the vector |
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory
-
-BK_ERANGE if size has reached representable limit
◆ vector_add_last()
Adds an element to the end of the vector.
- Parameters
-
me | the vector to add to |
data | the data to add to the vector |
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory
-
-BK_ERANGE if size has reached representable limit
◆ vector_capacity()
size_t vector_capacity |
( |
vector |
me | ) |
|
Gets the capacity that the internal storage of the vector is using.
- Parameters
-
- Returns
- the capacity that the internal storage of the vector is using
◆ vector_clear()
Clears the elements from the vector.
- Parameters
-
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory
◆ vector_copy_to_array()
void vector_copy_to_array |
( |
void *const |
arr, |
|
|
vector |
me |
|
) |
| |
Copies the vector to an array. Since it is a copy, the array may be modified without causing side effects to the vector 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 vector should be queried prior to calling this function, which also serves as the size of the newly-copied array.
- Parameters
-
arr | the initialized array to copy the vector to |
me | the vector to copy to the array |
◆ vector_destroy()
Frees the vector 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 vector to free from memory |
- Returns
- NULL
◆ vector_get_at()
bk_err vector_get_at |
( |
void *const |
data, |
|
|
vector |
me, |
|
|
const size_t |
index |
|
) |
| |
Copies the element at index of the vector to data. The pointer to the data being obtained should point to the data type which this vector holds. For example, if this vector 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 vector to copy from |
index | the index to copy from in the vector |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ vector_get_data()
void* vector_get_data |
( |
vector |
me | ) |
|
Gets the storage element of the vector structure. The storage element is contiguous in memory. The data pointer should be assigned to the correct array type. For example, if the vector holds integers, the data pointer should be assigned to an integer array. The size of the vector should be obtained prior to calling this function, which also serves as the size of the queried array. This pointer is not a copy, thus any modification to the data will cause the vector structure data to be modified. Operations using the vector functions may invalidate this pointer. The vector owns this memory, thus it should not be freed. This should not be used if the vector is empty.
- Parameters
-
me | the vector to get the storage element from |
- Returns
- the storage element of the vector
◆ vector_get_first()
Copies the first element of the vector to data. The pointer to the data being obtained should point to the data type which this vector holds. For example, if this vector 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 vector to copy from |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ vector_get_last()
Copies the last element of the vector to data. The pointer to the data being obtained should point to the data type which this vector holds. For example, if this vector 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 vector to copy from |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ vector_init()
vector vector_init |
( |
const size_t |
data_size | ) |
|
Initializes a vector.
- Parameters
-
data_size | the size of each element in the vector; must be positive |
- Returns
- the newly-initialized vector, or NULL if it was not successfully initialized due to either invalid input arguments or memory allocation error
◆ vector_is_empty()
Determines whether or not the vector is empty.
- Parameters
-
- Returns
- BK_TRUE if the vector is empty, otherwise BK_FALSE
◆ vector_remove_at()
Removes element based on its index.
- Parameters
-
me | the vector to remove from |
index | the location in the vector to remove the data from |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ vector_remove_first()
Removes the first element from the vector.
- Parameters
-
me | the vector to remove from |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ vector_remove_last()
Removes the last element from the vector.
- Parameters
-
me | the vector to remove from |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ vector_reserve()
Reserves space specified. If more space than specified is already reserved, then the previous space will be kept.
- Parameters
-
me | the vector to reserve space for |
size | the space to reserve |
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory
-
-BK_ERANGE if space to reserve exceeds representable limit
◆ vector_set_at()
bk_err vector_set_at |
( |
vector |
me, |
|
|
const size_t |
index, |
|
|
void *const |
data |
|
) |
| |
Sets the data for a specified element in the vector. The pointer to the data being passed in should point to the data type which this vector holds. For example, if this vector 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 vector to set data for |
index | the location to set data at in the vector |
data | the data to set at the location in the vector |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ vector_set_first()
Sets the data for the first element in the vector. The pointer to the data being passed in should point to the data type which this vector holds. For example, if this vector 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 vector to set data for |
data | the data to set at the start of the vector |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ vector_set_last()
Sets the data for the last element in the vector. The pointer to the data being passed in should point to the data type which this vector holds. For example, if this vector 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 vector to set data for |
data | the data to set at the end of the vector |
- Returns
- BK_OK if no error
-
-BK_EINVAL if invalid argument
◆ vector_size()
size_t vector_size |
( |
vector |
me | ) |
|
Gets the size being used by the vector.
- Parameters
-
- Returns
- the size being used by the vector
◆ vector_trim()
Sets the size of the vector buffer to the current size being used.
- Parameters
-
- Returns
- BK_OK if no error
-
-BK_ENOMEM if out of memory