diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2012-04-13 19:01:16 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-14 13:50:33 +0200 |
commit | 67d7f55db6a29bd96f3834979e0789a6a444320f (patch) | |
tree | ee388ba650b2489eae705758ebea79c81a727eb9 /src/corelib/tools/qhash.h | |
parent | 06a5904c8f1a9dd32b78afb9d95615f57a6d31aa (diff) |
qHash: two arguments support for simple integer types (and QChar)
Change-Id: I24bed73422fb1d2e90cf3dd4e5375e249b3dcac4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r-- | src/corelib/tools/qhash.h | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 533208da85..2bc6cc4e81 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -58,32 +58,32 @@ class QByteArray; class QString; class QStringRef; -inline uint qHash(char key) { return uint(key); } -inline uint qHash(uchar key) { return uint(key); } -inline uint qHash(signed char key) { return uint(key); } -inline uint qHash(ushort key) { return uint(key); } -inline uint qHash(short key) { return uint(key); } -inline uint qHash(uint key) { return key; } -inline uint qHash(int key) { return uint(key); } -inline uint qHash(ulong key) +inline uint qHash(char key, uint seed = 0) { return uint(key) ^ seed; } +inline uint qHash(uchar key, uint seed = 0) { return uint(key) ^ seed; } +inline uint qHash(signed char key, uint seed = 0) { return uint(key) ^ seed; } +inline uint qHash(ushort key, uint seed = 0) { return uint(key) ^ seed; } +inline uint qHash(short key, uint seed = 0) { return uint(key) ^ seed; } +inline uint qHash(uint key, uint seed = 0) { return key ^ seed; } +inline uint qHash(int key, uint seed = 0) { return uint(key) ^ seed; } +inline uint qHash(ulong key, uint seed = 0) { if (sizeof(ulong) > sizeof(uint)) { - return uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U)); + return uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U)) ^ seed; } else { - return uint(key & (~0U)); + return uint(key & (~0U)) ^ seed; } } -inline uint qHash(long key) { return qHash(ulong(key)); } -inline uint qHash(quint64 key) +inline uint qHash(long key, uint seed = 0) { return qHash(ulong(key), seed); } +inline uint qHash(quint64 key, uint seed = 0) { if (sizeof(quint64) > sizeof(uint)) { - return uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U)); + return uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U)) ^ seed; } else { - return uint(key & (~0U)); + return uint(key & (~0U)) ^ seed; } } -inline uint qHash(qint64 key) { return qHash(quint64(key)); } -inline uint qHash(QChar key) { return qHash(key.unicode()); } +inline uint qHash(qint64 key, uint seed = 0) { return qHash(quint64(key), seed); } +inline uint qHash(QChar key, uint seed = 0) { return qHash(key.unicode(), seed); } Q_CORE_EXPORT uint qHash(const QByteArray &key, uint seed = 0); Q_CORE_EXPORT uint qHash(const QString &key, uint seed = 0); Q_CORE_EXPORT uint qHash(const QStringRef &key, uint seed = 0); |