diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-12-03 09:14:27 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-12-04 06:00:21 +0000 |
commit | 793dbd8ee67ee8ad62dcb9b2304645293eabe837 (patch) | |
tree | 3ecd9ea302819fd00d22250d1943c8e06bd34b3a /src/corelib/tools/qhash.cpp | |
parent | 013abe320680b3dcd3f6d7e4fb4880e590ba10e6 (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.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 84eaed1ea1..fa9688340d 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 |