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

Method OnAdd

Source/Engine/Core/Collections/HashSetBase.h:368–398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

366
367 template<typename KeyComparableType>
368 BucketType* OnAdd(const KeyComparableType& key, bool checkUnique = true, bool nullIfNonUnique = false)
369 {
370 // Check if need to rehash elements (prevent many deleted elements that use too much of capacity)
371 if (_deletedCount * HASH_SET_DEFAULT_SLACK_SCALE > _size)
372 Compact();
373
374 // Ensure to have enough memory for the next item (in case of new element insertion)
375 EnsureCapacity(((_elementsCount + 1) * HASH_SET_DEFAULT_SLACK_SCALE + _deletedCount) / HASH_SET_DEFAULT_SLACK_SCALE);
376
377 // Find location of the item or place to insert it
378 FindPositionResult pos;
379 FindPosition(key, pos);
380
381 // Check if object has been already added
382 if (pos.ObjectIndex != -1)
383 {
384 if (checkUnique)
385 {
386 Platform::CheckFailed("That key has been already added to the collection.", __FILE__, __LINE__);
387 return nullptr;
388 }
389 if (nullIfNonUnique)
390 return nullptr;
391 return &_allocation.Get()[pos.ObjectIndex];
392 }
393
394 // Insert
395 ASSERT(pos.FreeSlotIndex != -1);
396 ++_elementsCount;
397 return &_allocation.Get()[pos.FreeSlotIndex];
398 }
399
400 void Compact()
401 {

Callers

nothing calls this directly

Calls 2

EnsureCapacityFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected