More qHash(T, uint) support
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Mon, 2 Jul 2012 08:01:56 +0000 (09:01 +0100)
committerQt by Nokia <qt-info@nokia.com>
Mon, 23 Jul 2012 17:57:07 +0000 (19:57 +0200)
Add the seed to QPair, QUuid, QPersistentModelIndex's qHash(), and fix
qHash documentation for them and for many other datatypes.

Change-Id: I1386f3ed42ee1a832371a242ee5c82895ba92c2b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/itemmodels/qabstractitemmodel.cpp
src/corelib/itemmodels/qabstractitemmodel.h
src/corelib/plugin/quuid.cpp
src/corelib/plugin/quuid.h
src/corelib/tools/qhash.cpp
src/corelib/tools/qhash.h

index 9e0e9c0..87bcb6d 100644 (file)
@@ -3517,11 +3517,13 @@ bool QAbstractListModel::dropMimeData(const QMimeData *data, Qt::DropAction acti
 */
 
 /*!
-    \fn uint qHash(const QPersistentModelIndex &index)
-    \since 4.5
+    \fn uint qHash(const QPersistentModelIndex &index, uint seed = 0)
+    \since 5.0
+    \relates QPersistentModelIndex
 
-    Returns a hash of the QPersistentModelIndex
- */
+    Returns a hash of the QPersistentModelIndex \a index, using \a seed to
+    seed the calculation.
+*/
 
 
 /*!
index 66af606..4cdafdd 100644 (file)
@@ -134,15 +134,15 @@ public:
     bool isValid() const;
 private:
     QPersistentModelIndexData *d;
-    friend uint qHash(const QPersistentModelIndex &);
+    friend uint qHash(const QPersistentModelIndex &, uint seed = 0);
 #ifndef QT_NO_DEBUG_STREAM
     friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
 #endif
 };
 Q_DECLARE_SHARED(QPersistentModelIndex)
 
-inline uint qHash(const QPersistentModelIndex &index)
-{ return qHash(index.d); }
+inline uint qHash(const QPersistentModelIndex &index, uint seed)
+{ return qHash(index.d, seed); }
 
 
 #ifndef QT_NO_DEBUG_STREAM
index bfe8dfc..952e418 100644 (file)
@@ -999,14 +999,17 @@ QDebug operator<<(QDebug dbg, const QUuid &id)
 }
 #endif
 
-/**
-    Returns a hash of the QUuid
- */
-uint qHash(const QUuid &uuid)
+/*!
+    \since 5.0
+    \relates QUuid
+    Returns a hash of the UUID \a uuid, using \a seed to seed the calculation.
+*/
+uint qHash(const QUuid &uuid, uint seed)
 {
     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]);
+            ^ ((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])
+            ^ seed;
 }
 
 
index e595613..7fd32a3 100644 (file)
@@ -227,7 +227,7 @@ Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QUuid &);
 Q_CORE_EXPORT QDebug operator<<(QDebug, const QUuid &);
 #endif
 
-Q_CORE_EXPORT uint qHash(const QUuid &uuid);
+Q_CORE_EXPORT uint qHash(const QUuid &uuid, uint seed = 0);
 
 QT_END_NAMESPACE
 
index 0a6d51c..97f846c 100644 (file)
@@ -1,3 +1,4 @@
+
 /****************************************************************************
 **
 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
@@ -570,104 +571,139 @@ void QHashData::checkSanity()
 #endif
 
 /*!
-    \fn uint qHash(const QPair<T1, T2> &key)
-    \since 4.3
+    \fn uint qHash(const QPair<T1, T2> &key, uint seed = 0)
+    \since 5.0
     \relates QHash
     
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 
     Types \c T1 and \c T2 must be supported by qHash().
 */
 
-/*! \fn uint qHash(char key)
+/*! \fn uint qHash(char key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(uchar key)
+/*! \fn uint qHash(uchar key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(signed char key)
+/*! \fn uint qHash(signed char key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(ushort key)
+/*! \fn uint qHash(ushort key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(short key)
+/*! \fn uint qHash(short key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(uint key)
+/*! \fn uint qHash(uint key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(int key)
+/*! \fn uint qHash(int key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(ulong key)
+/*! \fn uint qHash(ulong key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(long key)
+/*! \fn uint qHash(long key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(quint64 key)
+/*! \fn uint qHash(quint64 key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(qint64 key)
+/*! \fn uint qHash(qint64 key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(QChar key)
+/*! \fn uint qHash(QChar key, uint seed = 0)
     \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
 /*! \fn uint qHash(const QByteArray &key, uint seed = 0)
-    \fn uint qHash(const QBitArray &key, uint seed = 0)
-    \fn uint qHash(const QString &key, uint seed = 0)
-    \fn uint qHash(const QStringRef &key, uint seed = 0)
-    \fn uint qHash(QLatin1String key, uint seed = 0)
+    \relates QHash
+    \since 5.0
 
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
+*/
+
+/*! \fn uint qHash(const QBitArray &key, uint seed = 0)
     \relates QHash
     \since 5.0
 
-    Returns the hash value for the \a key, using \a seed to
-    seed the calculation.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
-/*! \fn uint qHash(const T *key)
+/*! \fn uint qHash(const QString &key, uint seed = 0)
     \relates QHash
+    \since 5.0
+
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
+*/
+
+/*! \fn uint qHash(const QStringRef &key, uint seed = 0)
+    \relates QHash
+    \since 5.0
+
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
+*/
+
+/*! \fn uint qHash(QLatin1String key, uint seed = 0)
+    \relates QHash
+    \since 5.0
+
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
+*/
+
+/*! \fn uint qHash(const T *key, uint seed = 0)
+    \relates QHash
+    \since 5.0
 
-    Returns the hash value for the \a key.
+    Returns the hash value for the \a key, using \a seed to seed the calculation.
 */
 
 /*!
index 8f01cd2..0c322cd 100644 (file)
@@ -103,11 +103,11 @@ template <class T> inline uint qHash(const T *key, uint seed = 0)
 #pragma warning( pop )
 #endif
 
-template <typename T1, typename T2> inline uint qHash(const QPair<T1, T2> &key)
+template <typename T1, typename T2> inline uint qHash(const QPair<T1, T2> &key, uint seed = 0)
 {
-    uint h1 = qHash(key.first);
-    uint h2 = qHash(key.second);
-    return ((h1 << 16) | (h1 >> 16)) ^ h2;
+    uint h1 = qHash(key.first, seed);
+    uint h2 = qHash(key.second, seed);
+    return ((h1 << 16) | (h1 >> 16)) ^ h2 ^ seed;
 }
 
 template<typename T> inline uint qHash(const T &t, uint seed) { return (qHash(t) ^ seed); }