Skip to content

Commit

Permalink
Add a qHash for QUuid
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ogoffart authored and Qt by Nokia committed Jul 19, 2011
1 parent d5bdbd7 commit 55d68a1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/corelib/plugin/quuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/corelib/plugin/quuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/auto/quuid/tst_quuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ private slots:
void threadUniqueness();
void processUniqueness();

void hash();

public:
// Variables
QUuid uuidA;
Expand Down Expand Up @@ -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"

0 comments on commit 55d68a1

Please sign in to comment.