implemented List_increaseCapacity_size
This commit is contained in:
@@ -14,19 +14,28 @@ List_ List_copy(const List_ src){
|
||||
return copy;
|
||||
}
|
||||
|
||||
void* List_expand_size(List_* self, u32 size_to_add){
|
||||
void List_increaseCapacity_size(List_* self, u32 size_to_add){
|
||||
u32 occupied_size = self->size;
|
||||
u32 expanded_alloc_size = self->allocated_size;
|
||||
if(expanded_alloc_size == 0)
|
||||
expanded_alloc_size = 64;
|
||||
self->size += size_to_add;
|
||||
while(self->size > expanded_alloc_size){
|
||||
expanded_alloc_size *= 2;
|
||||
u32 expanded_size = occupied_size + size_to_add;
|
||||
|
||||
if(self->allocated_size < expanded_size) {
|
||||
u32 expanded_alloc_size = self->allocated_size;
|
||||
if(expanded_alloc_size == 0)
|
||||
expanded_alloc_size = 32;
|
||||
while(expanded_alloc_size < expanded_size){
|
||||
expanded_alloc_size *= 2;
|
||||
}
|
||||
// if self->data is null, realloc acts like malloc
|
||||
self->data = realloc(self->data, expanded_alloc_size);
|
||||
self->allocated_size = expanded_alloc_size;
|
||||
}
|
||||
// if self->data is null, realloc acts like malloc
|
||||
self->data = realloc(self->data, expanded_alloc_size);
|
||||
self->allocated_size = expanded_alloc_size;
|
||||
return (u8*)(self->data) + occupied_size;
|
||||
}
|
||||
|
||||
void* List_expand_size(List_* self, u32 size_to_add){
|
||||
List_increaseCapacity_size(self, size_to_add);
|
||||
u8* empty_cell_ptr = (u8*)self->data + self->size;
|
||||
self->size += size_to_add;
|
||||
return empty_cell_ptr;
|
||||
}
|
||||
|
||||
void List_push_size(List_* self, void* values, u32 size){
|
||||
|
||||
Reference in New Issue
Block a user