mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 05:27:20 +00:00
[common] vector: implement item removal
This commit is contained in:
parent
bbd39b8185
commit
f0beedb5ba
@ -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);
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user