mirror of
https://github.com/bdnugget/nbnet.git
synced 2026-11-07 05:27:27 +00:00
Merge pull request #54 from nathhB/conn-vector-remove-rewrite
rewrite NBN_ConnectionVector_RemoveAt function in a simpler way
This commit is contained in:
1 file changed
+4
-11
@@ -1842,20 +1842,13 @@ static uint32_t NBN_ConnectionVector_RemoveAt(NBN_ConnectionVector *vector, unsi
|
||||
|
||||
if (conn == NULL) return 0;
|
||||
|
||||
// Rearrange the vector so that connections are stored contiguously in memory
|
||||
for (unsigned int i = position; i < vector->count - 1; i++)
|
||||
{
|
||||
NBN_Connection *conn = vector->connections[i];
|
||||
NBN_Connection *next_conn = vector->connections[i + 1];
|
||||
// Make sure that connections are stored contiguously in memory
|
||||
|
||||
assert(conn->vector_pos == (int)i);
|
||||
assert(next_conn->vector_pos == (int)(i + 1));
|
||||
|
||||
next_conn->vector_pos = i;
|
||||
vector->connections[i] = next_conn;
|
||||
}
|
||||
NBN_Connection *last_conn = vector->connections[vector->count - 1];
|
||||
|
||||
vector->connections[position] = last_conn;
|
||||
vector->connections[vector->count - 1] = NULL;
|
||||
last_conn->vector_pos = position; // last connection in the vector is moved to the position of the removed one
|
||||
vector->count--;
|
||||
|
||||
return conn->id;
|
||||
|
||||
Reference in new issue
Block a user