From 67d7f55db6a29bd96f3834979e0789a6a444320f Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 13 Apr 2012 19:01:16 +0100 Subject: [PATCH] qHash: two arguments support for simple integer types (and QChar) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I24bed73422fb1d2e90cf3dd4e5375e249b3dcac4 Reviewed-by: Thiago Macieira Reviewed-by: João Abecasis --- src/corelib/tools/qhash.h | 32 ++++++++++++++++---------------- 1 file 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);