diff --git a/Source/Engine/Core/Collections/HashSet.h b/Source/Engine/Core/Collections/HashSet.h index ab2601525..6751be0dc 100644 --- a/Source/Engine/Core/Collections/HashSet.h +++ b/Source/Engine/Core/Collections/HashSet.h @@ -408,7 +408,7 @@ public: template bool Add(const ItemType& item) { - Bucket* bucket = Base::OnAdd(item, false); + Bucket* bucket = Base::OnAdd(item, false, true); if (bucket) bucket->Occupy(item); return bucket != nullptr; @@ -421,7 +421,7 @@ public: /// True if element has been added to the collection, otherwise false if the element is already present. bool Add(T&& item) { - Bucket* bucket = Base::OnAdd(item, false); + Bucket* bucket = Base::OnAdd(item, false, true); if (bucket) bucket->Occupy(MoveTemp(item)); return bucket != nullptr; diff --git a/Source/Engine/Core/Collections/HashSetBase.h b/Source/Engine/Core/Collections/HashSetBase.h index 200e26b7b..488613d2b 100644 --- a/Source/Engine/Core/Collections/HashSetBase.h +++ b/Source/Engine/Core/Collections/HashSetBase.h @@ -359,7 +359,7 @@ protected: } template - BucketType* OnAdd(const KeyComparableType& key, bool checkUnique = true) + BucketType* OnAdd(const KeyComparableType& key, bool checkUnique = true, bool nullIfNonUnique = false) { // Check if need to rehash elements (prevent many deleted elements that use too much of capacity) if (_deletedCount * HASH_SET_DEFAULT_SLACK_SCALE > _size) @@ -380,6 +380,8 @@ protected: Platform::CheckFailed("That key has been already added to the collection.", __FILE__, __LINE__); return nullptr; } + if (nullIfNonUnique) + return nullptr; return &_allocation.Get()[pos.ObjectIndex]; }