still working on adding frames to config
This commit is contained in:
parent
3fa74e8f9e
commit
0591b6ca6e
10 changed files with 199 additions and 53 deletions
|
|
@ -37,6 +37,10 @@ void ARC_Handler_Remove(ARC_Handler *handler, void *data){
|
|||
}
|
||||
|
||||
void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t *index){
|
||||
if(!*ARC_Vector_Size(handler->data)){
|
||||
return;
|
||||
}
|
||||
|
||||
void *data = ARC_Vector_Get(handler->data, index);
|
||||
ARC_Vector_Add(handler->trash, data);
|
||||
ARC_Vector_RemoveIndex(handler->data, index);
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ struct ARC_Vector {
|
|||
|
||||
void ARC_Vector_Create(ARC_Vector **vector, uint32_t dataSize){
|
||||
*vector = (ARC_Vector *) malloc(sizeof(ARC_Vector));
|
||||
(*vector)->currentSize = (uint32_t *) malloc(sizeof(uint32_t));
|
||||
(*vector)->capacity = (uint32_t *) malloc(sizeof(uint32_t));
|
||||
(*vector)->dataSize = (uint32_t *) malloc(sizeof(uint32_t));
|
||||
(*vector)->data = (void *) malloc(dataSize);
|
||||
(*vector)->currentSize = (uint32_t *)malloc(sizeof(uint32_t));
|
||||
(*vector)->capacity = (uint32_t *)malloc(sizeof(uint32_t));
|
||||
(*vector)->dataSize = (uint32_t *)malloc(sizeof(uint32_t));
|
||||
(*vector)->data = (void *)malloc(dataSize);
|
||||
|
||||
*((*vector)->currentSize) = 0;
|
||||
*((*vector)->capacity) = 1;
|
||||
*((*vector)->dataSize) = dataSize;
|
||||
*(*vector)->currentSize = 0;
|
||||
*(*vector)->capacity = 1;
|
||||
*(*vector)->dataSize = dataSize;
|
||||
}
|
||||
|
||||
void ARC_Vector_Destroy(ARC_Vector *vector){
|
||||
|
|
@ -32,33 +32,36 @@ void ARC_Vector_Destroy(ARC_Vector *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)){
|
||||
*(vector->capacity) <<= 1;
|
||||
if(*vector->currentSize == *vector->capacity){
|
||||
if(!*vector->capacity){
|
||||
++*vector->capacity;
|
||||
}
|
||||
*vector->capacity <<= 1;
|
||||
|
||||
vector->data = (void *) realloc(vector->data, *(vector->dataSize) * *(vector->capacity));
|
||||
vector->data = (void *)realloc(vector->data, *vector->dataSize * *vector->capacity);
|
||||
}
|
||||
|
||||
memcpy(vector->data + (*(vector->currentSize) * *(vector->dataSize)), data, *(vector->dataSize));
|
||||
memcpy(vector->data + (*vector->currentSize * *vector->dataSize), data, *vector->dataSize);
|
||||
++*(vector->currentSize);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
--*(vector->currentSize);
|
||||
|
||||
if(*(vector->currentSize) != *(vector->capacity) >> 1){
|
||||
for(uint32_t i = 0; i <= *(vector->currentSize); i++){
|
||||
if(!compare(data, vector->data + (i * *(vector->dataSize)))){
|
||||
memcpy(vector->data + (i * *(vector->dataSize)), vector->data + ((i + 1) * *(vector->dataSize)), *(vector->currentSize - i) * *(vector->dataSize));
|
||||
if(*vector->currentSize != *vector->capacity >> 1){
|
||||
for(uint32_t i = 0; i <= *vector->currentSize; i++){
|
||||
if(!compare(data, vector->data + (i * *vector->dataSize))){
|
||||
memcpy(vector->data + (i * *vector->dataSize), vector->data + ((i + 1) * *vector->dataSize), *(vector->currentSize - i) * *vector->dataSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -67,13 +70,13 @@ void ARC_Vector_Remove(ARC_Vector *vector, void *data, ARC_Vector_CompareDataFn
|
|||
return;
|
||||
}
|
||||
|
||||
*(vector->capacity) >>= 1;
|
||||
void *temp = (void *) malloc(*(vector->dataSize) * *(vector->capacity));
|
||||
*vector->capacity >>= 1;
|
||||
void *temp = (void *) malloc(*vector->dataSize * *vector->capacity);
|
||||
|
||||
for(uint32_t i = 0; i <= *(vector->currentSize); i++){
|
||||
if(compare(data, vector->data + (i * *(vector->dataSize)))){
|
||||
memcpy(temp, vector->data, i * *(vector->dataSize));
|
||||
memcpy(temp + (i * *(vector->dataSize)), vector->data + ((i + 1) * *(vector->dataSize)), *(vector->currentSize - i) * *(vector->dataSize));
|
||||
for(uint32_t i = 0; i <= *vector->currentSize; i++){
|
||||
if(compare(data, vector->data + (i * *vector->dataSize))){
|
||||
memcpy(temp, vector->data, i * *vector->dataSize);
|
||||
memcpy(temp + (i * *vector->dataSize), vector->data + ((i + 1) * *vector->dataSize), *(vector->currentSize - i) * *vector->dataSize);
|
||||
free(vector->data);
|
||||
vector->data = temp;
|
||||
return;
|
||||
|
|
@ -84,21 +87,21 @@ void ARC_Vector_Remove(ARC_Vector *vector, void *data, ARC_Vector_CompareDataFn
|
|||
}
|
||||
|
||||
void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t *index){
|
||||
if(!*(vector->currentSize) || *index >= *(vector->currentSize)){
|
||||
if(!*vector->currentSize || *index >= *vector->currentSize){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
return;
|
||||
}
|
||||
|
||||
--*(vector->currentSize);
|
||||
if(*(vector->currentSize) != *(vector->capacity) >> 1){
|
||||
memcpy(vector->data + (*index * *(vector->dataSize)), vector->data + ((*index + 1) * *(vector->dataSize)), *(vector->currentSize - *index) * *(vector->dataSize));
|
||||
--*vector->currentSize;
|
||||
if(*vector->currentSize != *vector->capacity >> 1){
|
||||
memcpy(vector->data + (*index * *vector->dataSize), vector->data + ((*index + 1) * *vector->dataSize), *(vector->currentSize - *index) * *vector->dataSize);
|
||||
return;
|
||||
}
|
||||
|
||||
*(vector->capacity) >>= 1;
|
||||
void **temp = (void **) malloc(sizeof(void *) * (*(vector->capacity)));
|
||||
memcpy(temp, vector->data, *index * *(vector->dataSize));
|
||||
memcpy(temp + (*index * *(vector->dataSize)), vector->data + ((*index + 1) * *(vector->dataSize)), *(vector->currentSize - *index) * *(vector->dataSize));
|
||||
*vector->capacity >>= 1;
|
||||
void **temp = (void **)malloc(sizeof(void *) * (*(vector->capacity)));
|
||||
memcpy(temp, vector->data, *index * *vector->dataSize);
|
||||
memcpy(temp + (*index * *vector->dataSize), vector->data + ((*index + 1) * *vector->dataSize), *(vector->currentSize - *index) * *vector->dataSize);
|
||||
|
||||
free(vector->data);
|
||||
vector->data = temp;
|
||||
|
|
@ -106,4 +109,4 @@ void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t *index){
|
|||
|
||||
uint32_t *ARC_Vector_Size(ARC_Vector *vector){ return vector->currentSize; }
|
||||
|
||||
void *ARC_Vector_Get(ARC_Vector *vector, uint32_t *index){ return (void *)(uint8_t (*)[*(vector->dataSize)]) vector->data + (*index * *(vector->dataSize)); }
|
||||
void *ARC_Vector_Get(ARC_Vector *vector, uint32_t *index){ return (void *)(uint8_t (*)[*vector->dataSize]) vector->data + (*index * *vector->dataSize); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue