Fix HashSet::Add returning incorrect value
This commit is contained in:
@@ -408,7 +408,7 @@ public:
|
||||
template<typename ItemType>
|
||||
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:
|
||||
/// <returns>True if element has been added to the collection, otherwise false if the element is already present.</returns>
|
||||
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;
|
||||
|
||||
@@ -359,7 +359,7 @@ protected:
|
||||
}
|
||||
|
||||
template<typename KeyComparableType>
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user