updated vector to video version, will probably break a lot
This commit is contained in:
parent
c1e60a6d2f
commit
93dc0fa053
12 changed files with 461 additions and 97 deletions
|
|
@ -5,81 +5,100 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "arc/std/bool.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief a dynamic array type
|
||||
*/
|
||||
*/
|
||||
typedef struct ARC_Vector ARC_Vector;
|
||||
|
||||
/**
|
||||
* @brief data comparison function ptr
|
||||
* @brief a callback that allows the user to define a way to check the data stored in a vector for a match
|
||||
*
|
||||
* @param a first data struct
|
||||
* @param b second data struct
|
||||
* @param[in] dataA the first data to check
|
||||
* @param[in] dataB the second data to check
|
||||
*
|
||||
* @return 0 when a == b, TODO: return and ARC_Bool
|
||||
* @return ARC_True when dataA == dataB, and ARC_False otherwise
|
||||
*/
|
||||
typedef int32_t (* ARC_Vector_CompareDataFn)(void *a, void *b);
|
||||
typedef ARC_Bool (* ARC_Vector_CompareDataFn)(void *dataA, void *dataB);
|
||||
|
||||
/**
|
||||
* @brief creates ARC_Vector type
|
||||
* @brief creates an ARC_Vector which is an "expandable" array
|
||||
*
|
||||
* @param vector ARC_Vector to initialize
|
||||
*/
|
||||
void ARC_Vector_Create(ARC_Vector **vector);
|
||||
* @note for this basic implementation, the array will double in size every time the capacity is hit
|
||||
* @note the array will also half in size when the array is only half filled
|
||||
*
|
||||
* @param[out] vector ARC_Vector to initialize
|
||||
* @param[in] compareDataFn a callback that checks if data stored in the array matches,
|
||||
* if set to NULL and ARC_Vector_Remove is called, the pointer addresses will be compared
|
||||
*/
|
||||
void ARC_Vector_Create(ARC_Vector **vector, ARC_Vector_CompareDataFn *compareDataFn);
|
||||
|
||||
/**
|
||||
* @brief destroyes ARC_Vector type
|
||||
*/
|
||||
* @brief destroys an ARC_Vector
|
||||
*
|
||||
* @note this will not free the items stored in the vector
|
||||
* @note please make sure to clear and free the children before destroying an ARC_Vector
|
||||
*
|
||||
* @param[in] vector ARC_Vector to free
|
||||
*/
|
||||
void ARC_Vector_Destroy(ARC_Vector *vector);
|
||||
|
||||
/**
|
||||
* @brief adds value to vector
|
||||
* @brief adds an item to an ARC_Vector
|
||||
*
|
||||
* @param vector ARC_Vector to add to
|
||||
* @param data data that is being added
|
||||
*/
|
||||
* @note this will error if you add more than 4,294,967,295 items (the max value of an unsigned int 32)
|
||||
*
|
||||
* @param[in] vector ARC_Vector to add to
|
||||
* @param[in] data data that is being added
|
||||
*/
|
||||
void ARC_Vector_Add(ARC_Vector *vector, void *data);
|
||||
|
||||
/**
|
||||
* @brief remove from ARC_Vector
|
||||
* @brief removes an item from a matching item in an ARC_Vector
|
||||
*
|
||||
* @param vector ARC_Vector to remove from
|
||||
* @param data data that is being removed
|
||||
* @param compare comparison callback to get check if data should be removed
|
||||
*/
|
||||
void ARC_Vector_Remove(ARC_Vector *vector, void *data, ARC_Vector_CompareDataFn compare);
|
||||
* @note this function uses the ARC_Vector_CompareDataFn that the ARC_Vector was created with
|
||||
* @note this function will not throw an error if there is no match
|
||||
*
|
||||
* @param[in] vector ARC_Vector to remove from
|
||||
* @param[in] data matching data to remove
|
||||
*/
|
||||
void ARC_Vector_Remove(ARC_Vector *vector, void *data);
|
||||
|
||||
/**
|
||||
* @brief remove from ARC_Vector
|
||||
* @brief removes an item from an ARC_Vector at an index
|
||||
*
|
||||
* @param vector ARC_Vector to remove from
|
||||
* @param index index of data that is being removed
|
||||
*/
|
||||
* @note this function will error if trying to remove an index that is outside the bounds of the ARC_Vector
|
||||
*
|
||||
* @param[in] vector ARC_Vector to remove from
|
||||
* @param[in] index position of data to remove
|
||||
*/
|
||||
void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t index);
|
||||
|
||||
/**
|
||||
* @brief gets size of vector
|
||||
* @brief gets the current size of an ARC_Vector as an unsigned 32 bit integer
|
||||
*
|
||||
* @param vector ARC_Vector to get size from
|
||||
* @param[in] vector ARC_Vector to get current size from
|
||||
*
|
||||
* @return the pointer of the vectors size, TODO: don't pass as a pointer
|
||||
*/
|
||||
uint32_t ARC_Vector_Size(ARC_Vector *vector);
|
||||
* @return the current size as a unsigned 32 bit integer
|
||||
*/
|
||||
uint32_t ARC_Vector_GetSize(ARC_Vector *vector);
|
||||
|
||||
/**
|
||||
* @brief gets data from ARC_Vector at position index
|
||||
* @brief gets an item from an ARC_Vector at a position index
|
||||
*
|
||||
* @param vector ARC_Vector to get data from
|
||||
* @param index position of data in ARC_Vector
|
||||
* @note this function will error if trying to get an index that is outside the bounds of the ARC_Vector
|
||||
*
|
||||
* @return pointer to data on success, NULL on fail
|
||||
*/
|
||||
* @param[in] vector ARC_Vector to get data from
|
||||
* @param[in] index position of data to get
|
||||
*
|
||||
* @return a void * item, or NULL on error
|
||||
*/
|
||||
void *ARC_Vector_Get(ARC_Vector *vector, uint32_t index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //ARC_STD_VECTOR_H_
|
||||
#endif // !ARC_STD_VECTOR_H_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue