Reduce float hash collision by squaring valueHash 02/319802/2
authorANZ1217 <chihun.jeong@samsung.com>
Tue, 18 Feb 2025 05:17:59 +0000 (14:17 +0900)
committerANZ1217 <chihun.jeong@samsung.com>
Tue, 18 Feb 2025 05:59:53 +0000 (14:59 +0900)
Applied valueHash^2 to reduce frequent hash collisions in similar float values.

Change-Id: I8877b24e2936e8a3cbf7da3ca52998f74d75e65c

dali/public-api/object/property-map.cpp

index 4f078c742a54ec5a9f8c32cc44edb43970bb3fe2..eff823d108475e8a62b3feef2a5b8bc2c5669efc 100644 (file)
@@ -55,12 +55,14 @@ public:
       {
         // Use unordered hash operation.
         auto valueHash = iter.second.GetHash();
+        valueHash *= valueHash;
         hash += Dali::Internal::HashUtils::HashStringView(std::string_view(iter.first), valueHash);
       }
       for(const auto& iter : mIndexValueContainer)
       {
         // Use unordered hash operation.
         auto valueHash = iter.second.GetHash();
+        valueHash *= valueHash;
         hash += Dali::Internal::HashUtils::HashRawValue(iter.first, valueHash);
       }
 
@@ -157,6 +159,7 @@ void Property::Map::Insert(std::string key, Value value)
   {
     // Use unordered hash operation.
     auto valueHash = value.GetHash();
+    valueHash *= valueHash;
     mImpl->mHash += Dali::Internal::HashUtils::HashStringView(std::string_view(key), valueHash);
   }
   mImpl->mStringValueContainer.push_back(std::make_pair(std::move(key), std::move(value)));
@@ -173,6 +176,7 @@ void Property::Map::Insert(Property::Index key, Value value)
   {
     // Use unordered hash operation.
     auto valueHash = value.GetHash();
+    valueHash *= valueHash;
     mImpl->mHash += Dali::Internal::HashUtils::HashRawValue(key, valueHash);
   }
   mImpl->mIndexValueContainer.push_back(std::make_pair(key, std::move(value)));
@@ -376,6 +380,7 @@ bool Property::Map::Remove(Property::Index key)
       {
         // Use unordered hash operation.
         auto valueHash = iter->second.GetHash();
+        valueHash *= valueHash;
         mImpl->mHash -= Dali::Internal::HashUtils::HashRawValue(key, valueHash);
       }
       mImpl->mIndexValueContainer.erase(iter);
@@ -396,6 +401,7 @@ bool Property::Map::Remove(std::string_view key)
       {
         // Use unordered hash operation.
         auto valueHash = iter->second.GetHash();
+        valueHash *= valueHash;
         mImpl->mHash -= Dali::Internal::HashUtils::HashStringView(key, valueHash);
       }
       mImpl->mStringValueContainer.erase(iter);