mirror of
				https://github.com/gnif/LookingGlass.git
				synced 2025-10-31 04:31:57 +00:00 
			
		
		
		
	[common] vector: implement item removal
This commit is contained in:
		| @@ -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"); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Quantum
					Quantum