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.
|
Macros | |
#define | BKTHOMPS_VECTOR_START_SPACE 8 |
#define | BKTHOMPS_VECTOR_RESIZE_RATIO 1.5 |
#define BKTHOMPS_VECTOR_RESIZE_RATIO 1.5 |
#define BKTHOMPS_VECTOR_START_SPACE 8 |
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.
me | the vector to add data to |
arr | the array to copy data from |
size | the number of elements to copy |
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.
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 |
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.
me | the vector to add to |
data | the data to add to the vector |
Adds an element to the end of the vector.
me | the vector to add to |
data | the data to add to the vector |
size_t vector_capacity | ( | vector | me | ) |
Gets the capacity that the internal storage of the vector is using.
me | the vector to check |
Clears the elements from the vector.
me | the vector to clear |
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.
arr | the initialized array to copy the vector to |
me | the vector to copy to the array |
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.
me | the vector to free from memory |
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.
data | the data to copy to |
me | the vector to copy from |
index | the index to copy from in the vector |
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.
me | the vector to get the storage element from |
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.
data | the data to copy to |
me | the vector to copy from |
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.
data | the data to copy to |
me | the vector to copy from |
vector vector_init | ( | const size_t | data_size | ) |
Initializes a vector.
data_size | the size of each element in the vector; must be positive |
Determines whether or not the vector is empty.
me | the vector to check |
Removes element based on its index.
me | the vector to remove from |
index | the location in the vector to remove the data from |
Removes the first element from the vector.
me | the vector to remove from |
Removes the last element from the vector.
me | the vector to remove from |
Reserves space specified. If more space than specified is already reserved, then the previous space will be kept.
me | the vector to reserve space for |
size | the space to reserve |
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.
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 |
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.
me | the vector to set data for |
data | the data to set at the start of the vector |
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.
me | the vector to set data for |
data | the data to set at the end of the vector |
size_t vector_size | ( | vector | me | ) |
Gets the size being used by the vector.
me | the vector to check |