QNativeIpcKey: add qHash() function

Equality comparable types should define a qHash() function.

Change-Id: I1677fbefa3d09d49a292d369b808793f884c32e9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit c2310f8e03cf30222cea59b3c556d060e1710015)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Dennis Oberst 2023-07-14 11:49:18 +02:00 committed by Qt Cherry-pick Bot
parent abc9fd2023
commit ff157648d6
3 changed files with 29 additions and 0 deletions

View File

@ -482,6 +482,22 @@ void QNativeIpcKey::setNativeKey_internal(const QString &)
{
}
/*!
\fn size_t QNativeIpcKey::qHash(const QNativeIpcKey &ipcKey) noexcept
Returns the hash value for \a ipcKey, using a default seed of \c 0.
*/
/*!
\fn size_t QNativeIpcKey::qHash(const QNativeIpcKey &ipcKey, size_t seed) noexcept
Returns the hash value for \a ipcKey, using \a seed to seed the calculation.
*/
size_t qHash(const QNativeIpcKey &ipcKey, size_t seed) noexcept
{
return qHashMulti(seed, ipcKey.key, ipcKey.type());
}
/*!
\fn bool QNativeIpcKey::operator==(const QNativeIpcKey &lhs, const QNativeIpcKey &rhs) noexcept
\fn bool QNativeIpcKey::operator!=(const QNativeIpcKey &lhs, const QNativeIpcKey &rhs) noexcept

View File

@ -158,6 +158,10 @@ private:
constexpr bool isSlowPath() const noexcept
{ return Q_UNLIKELY(typeAndFlags.isExtended); }
friend Q_CORE_EXPORT size_t qHash(const QNativeIpcKey &ipcKey, size_t seed) noexcept;
friend size_t qHash(const QNativeIpcKey &ipcKey) noexcept
{ return qHash(ipcKey, 0); }
friend bool operator==(const QNativeIpcKey &lhs, const QNativeIpcKey &rhs) noexcept
{
if (lhs.key != rhs.key)

View File

@ -16,6 +16,7 @@ private slots:
void construct();
void getSetCheck();
void equality();
void hash();
void swap();
void toString_data();
void toString();
@ -182,6 +183,14 @@ void tst_QNativeIpcKey::equality()
QVERIFY(!(key1 != key2));
}
void tst_QNativeIpcKey::hash()
{
QNativeIpcKey key1("key1", QNativeIpcKey::DefaultTypeForOs);
QNativeIpcKey key2(key1);
QCOMPARE_EQ(qHash(key1), qHash(key2));
QCOMPARE_EQ(qHash(key1, 123), qHash(key2, 123));
}
void tst_QNativeIpcKey::swap()
{
QNativeIpcKey key1("key1", QNativeIpcKey::Type::PosixRealtime);