summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-12-03 09:14:27 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-12-03 15:46:45 +0000
commit8e7bcedb659a4d9a052a0ddea375abd253e8925f (patch)
treeee888b6be102375345e4ecc93dd90f152876f7bc /src/corelib/tools/qhash.cpp
parent6bc1a1ec2f630d38d87ff14c8ab4c3fa5eba35be (diff)
Add a qHashEquals() method and use it to compare keys in QHash
In some cases, the default equality operator for a class is not suitable for using in hashing (for example because it uses fuzzy comparisons). Add a qHashEquals() method that by default uses the equality operator, but allows to tailor the operations that should be used when using the class as a key in QHash. Task-number: QTBUG-88966 Change-Id: I346cf0e6e923277a8b42a79e50342a1c2511fd80 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 5d8b586e73e37070b0303bee24372550854637eb) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib/tools/qhash.cpp')
-rw-r--r--src/corelib/tools/qhash.cpp15
1 files changed, 15 insertions, 0 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