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
|
|
@ -37,8 +37,8 @@ void ARC_Handler_Remove(ARC_Handler *handler, void *data, ARC_Handler_CompareDat
|
|||
ARC_Vector_Remove(handler->data, data, (ARC_Vector_CompareDataFn) compare);
|
||||
}
|
||||
|
||||
void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t *index){
|
||||
if(!*ARC_Vector_Size(handler->data)){
|
||||
void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t index){
|
||||
if(ARC_Vector_Size(handler->data) == 0){
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -48,31 +48,31 @@ void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t *index){
|
|||
}
|
||||
|
||||
void ARC_Handler_Iterate(ARC_Handler *handler, ARC_Handler_DataFn datafn){
|
||||
for(uint32_t i = 0; i < *ARC_Vector_Size(handler->data); i++){
|
||||
datafn(ARC_Vector_Get(handler->data, &i));
|
||||
for(uint32_t i = 0; i < ARC_Vector_Size(handler->data); i++){
|
||||
datafn(ARC_Vector_Get(handler->data, i));
|
||||
}
|
||||
}
|
||||
|
||||
void ARC_Handler_Clear(ARC_Handler *handler){
|
||||
uint32_t zeroIndex = 0;
|
||||
while(*ARC_Vector_Size(handler->data)){
|
||||
ARC_Handler_RemoveIndex(handler, &zeroIndex);
|
||||
while(ARC_Vector_Size(handler->data)){
|
||||
ARC_Handler_RemoveIndex(handler, zeroIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void ARC_Handler_Clean(ARC_Handler *handler){
|
||||
uint32_t i = 0;
|
||||
while(*ARC_Vector_Size(handler->trash)){
|
||||
void *data = ARC_Vector_Get(handler->trash, &i);
|
||||
while(ARC_Vector_Size(handler->trash)){
|
||||
void *data = ARC_Vector_Get(handler->trash, i);
|
||||
|
||||
if(handler->cleanfn){
|
||||
handler->cleanfn(data);
|
||||
}
|
||||
|
||||
ARC_Vector_RemoveIndex(handler->trash, &i);
|
||||
ARC_Vector_RemoveIndex(handler->trash, i);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t *ARC_Handler_Size(ARC_Handler *handler){
|
||||
uint32_t ARC_Handler_Size(ARC_Handler *handler){
|
||||
return ARC_Vector_Size(handler->data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ void ARC_Queue_Push(ARC_Queue *queue, void *data){
|
|||
void *ARC_Queue_Pop(ARC_Queue *queue){
|
||||
if(queue->currentSize == 0){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
ARC_DEBUG_ERR("ARC_Queue_Pop(queue) called, but queue was not empty");
|
||||
ARC_DEBUG_ERR("ARC_Queue_Pop(queue) called, but queue was empty");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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