diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 9e0e9c06de..87bcb6dfdc 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -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. +*/ /*! diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index 66af606dac..4cdafdd9d8 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -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 diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index bfe8dfc3c4..952e41851a 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -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; } diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index e595613e8f..7fd32a307b 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -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 diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 0a6d51ced0..97f846c6c8 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -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 &key) - \since 4.3 + \fn uint qHash(const QPair &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) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(uchar key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(signed char key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(ushort key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(short key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(uint key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(int key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(ulong key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(long key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(quint64 key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(qint64 key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \fn uint qHash(QChar key) - \relates QHash - - Returns the hash value for the \a key. -*/ - -/*! \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) - +/*! \fn uint qHash(char 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(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, 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(ushort 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(short 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(uint 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(int 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(ulong 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(long 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(quint64 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(qint64 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(QChar 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 QByteArray &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. +*/ + +/*! \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, using \a seed to seed the calculation. */ /*! diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 8f01cd2d91..0c322cddcf 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -103,11 +103,11 @@ template inline uint qHash(const T *key, uint seed = 0) #pragma warning( pop ) #endif -template inline uint qHash(const QPair &key) +template inline uint qHash(const QPair &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 inline uint qHash(const T &t, uint seed) { return (qHash(t) ^ seed); }