summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qhash.cpp15
-rw-r--r--src/corelib/tools/qhash.h2
-rw-r--r--src/corelib/tools/qhashfunctions.h6
3 files changed, 22 insertions, 1 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 112a492526..1087f21564 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -1074,6 +1074,21 @@ size_t qHash(long double key, size_t seed) noexcept
Returns the hash value for the \a key, using \a seed to seed the calculation.
*/
+/*! \fn template<typename T> bool qHashEquals(const T &a, const T &b)
+ \relates QHash
+ \since 6.0
+ \internal
+
+ This method is being used by QHash to compare two keys. Returns true if the
+ keys \a a and \a b are considered equal for hashing purposes.
+
+ The default implementation returns the result of (a == b). It can be reimplemented
+ for a certain type if the equality operator is not suitable for hashing purposes.
+ This is for example the case if the equality operator uses qFuzzyCompare to compare
+ floating point values.
+*/
+
+
/*!
\class QHash
\inmodule QtCore
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 5dc88943fc..70e98bed60 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -560,7 +560,7 @@ struct Data
return iterator{ this, bucket };
} else {
Node &n = s.atOffset(offset);
- if (n.key == key)
+ if (qHashEquals(n.key, key))
return iterator{ this, bucket };
}
bucket = nextBucket(bucket);
diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h
index a03f659b52..25f9c1f1e4 100644
--- a/src/corelib/tools/qhashfunctions.h
+++ b/src/corelib/tools/qhashfunctions.h
@@ -178,6 +178,12 @@ template <typename T, std::enable_if_t<QHashPrivate::HasQHashSingleArgOverload<T
size_t qHash(const T &t, size_t seed) noexcept(noexcept(qHash(t)))
{ return qHash(t) ^ seed; }
+template<typename T>
+bool qHashEquals(const T &a, const T &b)
+{
+ return a == b;
+}
+
namespace QtPrivate {
struct QHashCombine