Removes the element at specified iterator position. The element iterator to remove.
| 302 | /// </summary> |
| 303 | /// <param name="i">The element iterator to remove.</param> |
| 304 | void Remove(const Iterator& i) |
| 305 | { |
| 306 | if (IsEmpty()) |
| 307 | return; |
| 308 | ASSERT(i._collection == this); |
| 309 | ASSERT(i._chunkIndex < _chunks.Count() && i._index < ChunkSize); |
| 310 | ASSERT(i.Index() < Count()); |
| 311 | |
| 312 | auto lastChunkIndex = (_count - 1) / ChunkSize; |
| 313 | auto lastIndex = (_count - 1) % ChunkSize; |
| 314 | auto& lastChunk = *_chunks[lastChunkIndex]; |
| 315 | |
| 316 | // Check if remove element from the last chunk |
| 317 | if (i._chunkIndex == lastChunkIndex) |
| 318 | { |
| 319 | // Remove that item |
| 320 | lastChunk.RemoveAt(i._index); |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | // Swap that item with the last item from the last chunk |
| 325 | (*_chunks[i._chunkIndex])[i._index] = lastChunk[lastIndex]; |
| 326 | lastChunk.RemoveLast(); |
| 327 | } |
| 328 | |
| 329 | _count--; |
| 330 | } |
| 331 | |
| 332 | /// <summary> |
| 333 | /// Clears the collection but without changing its capacity. |