diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2012-07-02 09:01:56 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-23 19:57:07 +0200 |
commit | 58ec01e278496bdaaee05546beb543a119de4277 (patch) | |
tree | 7a4437101eb0acaff913ad4696626b2b8cfa149d /src/corelib | |
parent | acbfb4d777474aadd28136141082a8114d4310ac (diff) |
More qHash(T, uint) support
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>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 10 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 6 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.cpp | 15 | ||||
-rw-r--r-- | src/corelib/plugin/quuid.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qhash.cpp | 106 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 8 |
6 files changed, 94 insertions, 53 deletions
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<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. */ /*! 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 <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); } |