f***ed up and needed to rework packages
This commit is contained in:
parent
f4592ae8d0
commit
b43ab1702f
73 changed files with 194 additions and 2045 deletions
|
|
@ -6,58 +6,53 @@
|
|||
#include <string.h>
|
||||
|
||||
struct ARC_Vector {
|
||||
uint32_t *currentSize, *capacity;
|
||||
uint32_t currentSize, capacity;
|
||||
void **data;
|
||||
};
|
||||
|
||||
void ARC_Vector_Create(ARC_Vector **vector){
|
||||
*vector = (ARC_Vector *) malloc(sizeof(ARC_Vector));
|
||||
(*vector)->currentSize = (uint32_t *)malloc(sizeof(uint32_t));
|
||||
(*vector)->capacity = (uint32_t *)malloc(sizeof(uint32_t));
|
||||
(*vector)->data = (void **)malloc(sizeof(void *));
|
||||
|
||||
*(*vector)->currentSize = 0;
|
||||
*(*vector)->capacity = 1;
|
||||
(*vector)->currentSize = 0;
|
||||
(*vector)->capacity = 1;
|
||||
(*vector)->data = (void **)malloc(sizeof(void *));
|
||||
}
|
||||
|
||||
void ARC_Vector_Destroy(ARC_Vector *vector){
|
||||
free(vector->currentSize);
|
||||
free(vector->capacity);
|
||||
free(vector->data);
|
||||
free(vector);
|
||||
}
|
||||
|
||||
void ARC_Vector_Add(ARC_Vector *vector, void *data){
|
||||
if(*vector->currentSize == ~((uint32_t)0)){
|
||||
if(vector->currentSize == ~((uint32_t)0)){
|
||||
arc_errno = ARC_ERRNO_OVERFLOW;
|
||||
return;
|
||||
}
|
||||
|
||||
if(*vector->currentSize == *vector->capacity){
|
||||
if(!*vector->capacity){
|
||||
++*vector->capacity;
|
||||
if(vector->currentSize == vector->capacity){
|
||||
if(!vector->capacity){
|
||||
++vector->capacity;
|
||||
}
|
||||
*vector->capacity <<= 1;
|
||||
vector->capacity <<= 1;
|
||||
|
||||
vector->data = (void *)realloc(vector->data, sizeof(void *) * *vector->capacity);
|
||||
vector->data = (void *)realloc(vector->data, sizeof(void *) * vector->capacity);
|
||||
}
|
||||
|
||||
vector->data[*vector->currentSize] = data;
|
||||
++*(vector->currentSize);
|
||||
vector->data[vector->currentSize] = data;
|
||||
++(vector->currentSize);
|
||||
}
|
||||
|
||||
//this function removes the redundant checking currentSize and index that would happen if ARC_Vector_Remove called ARC_Vector_RemoveIndex
|
||||
void ARC_Vector_RemoveIndexNoCheck(ARC_Vector *vector, uint32_t *index);
|
||||
void ARC_Vector_RemoveIndexNoCheck(ARC_Vector *vector, uint32_t index);
|
||||
|
||||
void ARC_Vector_Remove(ARC_Vector *vector, void *data, ARC_Vector_CompareDataFn compare){
|
||||
if(!*vector->currentSize){
|
||||
if(!vector->currentSize){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
return;
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < *vector->currentSize; i++){
|
||||
for(uint32_t i = 0; i < vector->currentSize; i++){
|
||||
if(!compare(data, vector->data[i])){
|
||||
ARC_Vector_RemoveIndexNoCheck(vector, &i);
|
||||
ARC_Vector_RemoveIndexNoCheck(vector, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -66,8 +61,8 @@ void ARC_Vector_Remove(ARC_Vector *vector, void *data, ARC_Vector_CompareDataFn
|
|||
arc_errno = ARC_ERRNO_DATA;
|
||||
}
|
||||
|
||||
void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t *index){
|
||||
if(!*vector->currentSize || *index >= *vector->currentSize){
|
||||
void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t index){
|
||||
if(!vector->currentSize || index >= vector->currentSize){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
return;
|
||||
}
|
||||
|
|
@ -75,36 +70,36 @@ void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t *index){
|
|||
ARC_Vector_RemoveIndexNoCheck(vector, index);
|
||||
}
|
||||
|
||||
void ARC_Vector_RemoveIndexNoCheck(ARC_Vector *vector, uint32_t *index){
|
||||
for(uint32_t i = *index; i <= *vector->currentSize; i++){
|
||||
if(i + 1 >= *vector->currentSize - 1){
|
||||
void ARC_Vector_RemoveIndexNoCheck(ARC_Vector *vector, uint32_t index){
|
||||
for(uint32_t i = index; i <= vector->currentSize; i++){
|
||||
if(i + 1 >= vector->currentSize - 1){
|
||||
break;
|
||||
}
|
||||
vector->data[i] = vector->data[i + 1];
|
||||
}
|
||||
|
||||
--*vector->currentSize;
|
||||
--vector->currentSize;
|
||||
|
||||
if(*vector->currentSize != *vector->capacity >> 1){
|
||||
if(vector->currentSize != vector->capacity >> 1){
|
||||
return;
|
||||
}
|
||||
|
||||
*vector->capacity >>= 1;
|
||||
if(*vector->capacity <= 0){
|
||||
*vector->capacity = 1;
|
||||
vector->capacity >>= 1;
|
||||
if(vector->capacity <= 0){
|
||||
vector->capacity = 1;
|
||||
}
|
||||
|
||||
vector->data = (void *)realloc(vector->data, sizeof(void *) * *vector->capacity);
|
||||
vector->data = (void *)realloc(vector->data, sizeof(void *) * vector->capacity);
|
||||
}
|
||||
|
||||
uint32_t *ARC_Vector_Size(ARC_Vector *vector){
|
||||
uint32_t ARC_Vector_Size(ARC_Vector *vector){
|
||||
return vector->currentSize;
|
||||
}
|
||||
|
||||
void *ARC_Vector_Get(ARC_Vector *vector, uint32_t *index){
|
||||
if(*index >= *vector->currentSize){
|
||||
void *ARC_Vector_Get(ARC_Vector *vector, uint32_t index){
|
||||
if(index >= vector->currentSize){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return vector->data[*index];
|
||||
return vector->data[index];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue