[common] vector: implement item removal

This commit is contained in:
Quantum 2021-08-28 06:33:16 -04:00 committed by Geoffrey McRae
parent bbd39b8185
commit f0beedb5ba
2 changed files with 11 additions and 0 deletions

View file

@ -51,6 +51,7 @@ inline static void * vector_data(Vector * vector)
void * vector_push(Vector * vector, void * item);
void vector_pop(Vector * vector);
void vector_remove(Vector * vector, size_t index);
void vector_at(Vector * vector, size_t index, void * data);
void * vector_ptrTo(Vector * vector, size_t index);
void vector_clear(Vector * vector);

View file

@ -99,6 +99,16 @@ void vector_pop(Vector * vector)
--vector->size;
}
void vector_remove(Vector * vector, size_t index)
{
DEBUG_ASSERT(index < vector->size && "Attempting to remove non-existent index!");
memmove((char *)vector->data + index * vector->itemSize,
(char *)vector->data + (index + 1) * vector->itemSize,
(vector->size - index - 1) * vector->itemSize
);
--vector->size;
}
void vector_at(Vector * vector, size_t index, void * data)
{
DEBUG_ASSERT(index < vector->size && "Out of bounds access");