MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Remove

Method Remove

Source/Engine/Core/Collections/ChunkedArray.h:304–330  ·  view source on GitHub ↗

Removes the element at specified iterator position. The element iterator to remove.

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 6

CountFunction · 0.85
RemoveLastMethod · 0.80
IsEmptyFunction · 0.70
CountMethod · 0.45
IndexMethod · 0.45
RemoveAtMethod · 0.45

Tested by

no test coverage detected