Add a qHash for QUuid
Change-Id: Ib0d9a765b8db3b34aa20d510de501c72a54cacbe Reviewed-on: http://codereview.qt.nokia.com/1743 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Xizhi Zhu <xizhi.zhu@nokia.com> Reviewed-by: João Abecasis <joao.abecasis@nokia.com>bb10
parent
d5bdbd70b3
commit
55d68a16aa
|
|
@ -927,4 +927,15 @@ QUuid QUuid::createUuid()
|
|||
guid; otherwise returns false.
|
||||
*/
|
||||
|
||||
/**
|
||||
Returns a hash of the QUuid
|
||||
*/
|
||||
uint qHash(const QUuid &uuid)
|
||||
{
|
||||
return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16)
|
||||
^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3])
|
||||
^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7]);
|
||||
}
|
||||
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -189,6 +189,8 @@ Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QUuid &);
|
|||
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUuid &);
|
||||
#endif
|
||||
|
||||
Q_CORE_EXPORT uint qHash(const QUuid &uuid);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_END_HEADER
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ private slots:
|
|||
void threadUniqueness();
|
||||
void processUniqueness();
|
||||
|
||||
void hash();
|
||||
|
||||
public:
|
||||
// Variables
|
||||
QUuid uuidA;
|
||||
|
|
@ -322,5 +324,14 @@ void tst_QUuid::processUniqueness()
|
|||
QVERIFY(processOneOutput != processTwoOutput);
|
||||
}
|
||||
|
||||
void tst_QUuid::hash()
|
||||
{
|
||||
uint h = qHash(uuidA);
|
||||
QCOMPARE(qHash(uuidA), h);
|
||||
QCOMPARE(qHash(QUuid(uuidA.toString())), h);
|
||||
}
|
||||
|
||||
|
||||
|
||||
QTEST_MAIN(tst_QUuid)
|
||||
#include "tst_quuid.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue