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>
This commit is contained in:
Giuseppe D'Angelo 2012-07-02 09:01:56 +01:00 committed by Qt by Nokia
parent acbfb4d777
commit 58ec01e278
6 changed files with 144 additions and 103 deletions

View 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.
*/
/*!

View 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

View 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;
}

View 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

View 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)
\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.
*/
/*!

View 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); }