diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-01-31 12:11:54 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-04-09 20:03:25 +0200 |
commit | c6cdf38e752c22babdbe645366bdfb7ce51d01ff (patch) | |
tree | 450b02523cb5a16791674ad1d06fb68c72eac971 /src/corelib | |
parent | 775945137b6ef62de9a7d416b1fe59d79006ba82 (diff) |
Change qHash() to work with size_t instead of uint
This is required, so that QHash and QSet can hold more
than 2^32 items on 64 bit platforms.
The actual hashing functions for strings are still 32bit, this will
be changed in a follow-up commit.
Change-Id: I4372125252486075ff3a0b45ecfa818359fe103b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib')
52 files changed, 161 insertions, 166 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp index d30ad50ffc..1f2c505a02 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp @@ -149,7 +149,7 @@ inline bool operator==(const Employee &e1, const Employee &e2) && e1.dateOfBirth() == e2.dateOfBirth(); } -inline uint qHash(const Employee &key, uint seed) +inline size_t qHash(const Employee &key, size_t seed) { return qHash(key.name(), seed) ^ key.dateOfBirth().day(); } @@ -312,7 +312,7 @@ qDeleteAll(hash2.keyBegin(), hash2.keyEnd()); //! [28] //! [qhashbits] -inline uint qHash(const std::vector<int> &key, uint seed = 0) +inline size_t qHash(const std::vector<int> &key, size_t seed = 0) { if (key.empty()) return seed; @@ -322,14 +322,14 @@ inline uint qHash(const std::vector<int> &key, uint seed = 0) //! [qhashbits] //! [qhashrange] -inline uint qHash(const std::vector<int> &key, uint seed = 0) +inline size_t qHash(const std::vector<int> &key, size_t seed = 0) { return qHashRange(key.begin(), key.end(), seed); } //! [qhashrange] //! [qhashrangecommutative] -inline uint qHash(const std::unordered_set<int> &key, uint seed = 0) +inline size_t qHash(const std::unordered_set<int> &key, size_t seed = 0) { return qHashRangeCommutative(key.begin(), key.end(), seed); } @@ -348,9 +348,9 @@ qHash(qMakePair(key.first, key.second), seed); //! [31] //! [32] -uint qHash(K key); -uint qHash(const K &key); +size_t qHash(K key); +size_t qHash(const K &key); -uint qHash(K key, uint seed); -uint qHash(const K &key, uint seed); +size_t qHash(K key, size_t seed); +size_t qHash(const K &key, size_t seed); //! [32] diff --git a/src/corelib/io/qfilesystemwatcher_win_p.h b/src/corelib/io/qfilesystemwatcher_win_p.h index 272591ce7a..9d74ca3f61 100644 --- a/src/corelib/io/qfilesystemwatcher_win_p.h +++ b/src/corelib/io/qfilesystemwatcher_win_p.h @@ -142,7 +142,7 @@ public: Q_DECLARE_TYPEINFO(QFileSystemWatcherPathKey, Q_MOVABLE_TYPE); -inline uint qHash(const QFileSystemWatcherPathKey &key) { return qHash(key.toCaseFolded()); } +inline size_t qHash(const QFileSystemWatcherPathKey &key) { return qHash(key.toCaseFolded()); } class QWindowsFileSystemWatcherEngineThread : public QThread { diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 3e7d8e113c..49570697ef 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -4116,7 +4116,7 @@ QList<QUrl> QUrl::fromStringList(const QStringList &urls, ParsingMode mode) \relates QHash \since 5.0 */ -uint qHash(const QUrl &url, uint seed) noexcept +size_t qHash(const QUrl &url, size_t seed) noexcept { if (!url.d) return qHash(-1, seed); // the hash of an unset port (-1) diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index edf5ee42d7..0425502a52 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -119,7 +119,7 @@ class QTypeInfo<QUrlTwoFlags<E1, E2> > : public QTypeInfoMerger<QUrlTwoFlags<E1, class QUrl; // qHash is a friend, but we can't use default arguments for friends (§8.3.6.4) -Q_CORE_EXPORT uint qHash(const QUrl &url, uint seed = 0) noexcept; +Q_CORE_EXPORT size_t qHash(const QUrl &url, size_t seed = 0) noexcept; class Q_CORE_EXPORT QUrl { @@ -356,7 +356,7 @@ public: static QList<QUrl> fromStringList(const QStringList &uris, ParsingMode mode = TolerantMode); static void setIdnWhitelist(const QStringList &); - friend Q_CORE_EXPORT uint qHash(const QUrl &url, uint seed) noexcept; + friend Q_CORE_EXPORT size_t qHash(const QUrl &url, size_t seed) noexcept; private: QUrlPrivate *d; diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp index 8d80a2d8bd..325a0c2ba3 100644 --- a/src/corelib/io/qurlquery.cpp +++ b/src/corelib/io/qurlquery.cpp @@ -434,7 +434,7 @@ bool QUrlQuery::operator ==(const QUrlQuery &other) const Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QUrlQuery &key, uint seed) noexcept +size_t qHash(const QUrlQuery &key, size_t seed) noexcept { if (const QUrlQueryPrivate *d = key.d) { QtPrivate::QHashCombine hash; diff --git a/src/corelib/io/qurlquery.h b/src/corelib/io/qurlquery.h index 89d0f88059..0be2cafb0b 100644 --- a/src/corelib/io/qurlquery.h +++ b/src/corelib/io/qurlquery.h @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE -Q_CORE_EXPORT uint qHash(const QUrlQuery &key, uint seed = 0) noexcept; +Q_CORE_EXPORT size_t qHash(const QUrlQuery &key, size_t seed = 0) noexcept; class QUrlQueryPrivate; class Q_CORE_EXPORT QUrlQuery @@ -109,7 +109,7 @@ public: private: friend class QUrl; - friend Q_CORE_EXPORT uint qHash(const QUrlQuery &key, uint seed) noexcept; + friend Q_CORE_EXPORT size_t qHash(const QUrlQuery &key, size_t seed) noexcept; QSharedDataPointer<QUrlQueryPrivate> d; public: typedef QSharedDataPointer<QUrlQueryPrivate> DataPtr; diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 57a6c2f239..3bc3b546da 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -3978,7 +3978,7 @@ bool QAbstractListModel::dropMimeData(const QMimeData *data, Qt::DropAction acti */ /*! - \fn uint qHash(const QPersistentModelIndex &index, uint seed = 0) + \fn size_t qHash(const QPersistentModelIndex &index, size_t seed = 0) \since 5.0 \relates QPersistentModelIndex diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index 2cc1bd8ce6..86ff361ccb 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -103,7 +103,7 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QModelIndex &); class QPersistentModelIndexData; // qHash is a friend, but we can't use default arguments for friends (§8.3.6.4) -uint qHash(const QPersistentModelIndex &index, uint seed = 0) noexcept; +size_t qHash(const QPersistentModelIndex &index, size_t seed = 0) noexcept; class Q_CORE_EXPORT QPersistentModelIndex { @@ -141,14 +141,14 @@ public: bool isValid() const; private: QPersistentModelIndexData *d; - friend uint qHash(const QPersistentModelIndex &, uint seed) noexcept; + friend size_t qHash(const QPersistentModelIndex &, size_t seed) noexcept; #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, uint seed) noexcept +inline size_t qHash(const QPersistentModelIndex &index, size_t seed) noexcept { return qHash(index.d, seed); } @@ -461,8 +461,8 @@ inline QVariant QModelIndex::data(int arole) const inline Qt::ItemFlags QModelIndex::flags() const { return m ? m->flags(*this) : Qt::ItemFlags(); } -inline uint qHash(const QModelIndex &index) noexcept -{ return uint((uint(index.row()) << 4) + index.column() + index.internalId()); } +inline size_t qHash(const QModelIndex &index, size_t seed) noexcept +{ return size_t((size_t(index.row()) << 4) + size_t(index.column()) + index.internalId()) ^ seed; } QT_END_NAMESPACE diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index 5421eb2afa..a1badc7693 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -223,9 +223,6 @@ private: Q_DECLARE_OPERATORS_FOR_FLAGS(QItemSelectionModel::SelectionFlags) -// dummy implentation of qHash() necessary for instantiating QList<QItemSelectionRange>::toSet() with MSVC -inline uint qHash(const QItemSelectionRange &) { return 0; } - #ifdef Q_CC_MSVC /* diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp index de450c68f4..17a6effe03 100644 --- a/src/corelib/mimetypes/qmimetype.cpp +++ b/src/corelib/mimetypes/qmimetype.cpp @@ -192,7 +192,7 @@ bool QMimeType::operator==(const QMimeType &other) const Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QMimeType &key, uint seed) noexcept +size_t qHash(const QMimeType &key, size_t seed) noexcept { return qHash(key.d->name, seed); } diff --git a/src/corelib/mimetypes/qmimetype.h b/src/corelib/mimetypes/qmimetype.h index df1b60f2ce..5aabbb449e 100644 --- a/src/corelib/mimetypes/qmimetype.h +++ b/src/corelib/mimetypes/qmimetype.h @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE class QMimeTypePrivate; class QMimeType; -Q_CORE_EXPORT uint qHash(const QMimeType &key, uint seed = 0) noexcept; +Q_CORE_EXPORT size_t qHash(const QMimeType &key, size_t seed = 0) noexcept; class Q_CORE_EXPORT QMimeType { @@ -119,7 +119,7 @@ protected: friend class QMimeXMLProvider; friend class QMimeBinaryProvider; friend class QMimeTypePrivate; - friend Q_CORE_EXPORT uint qHash(const QMimeType &key, uint seed) noexcept; + friend Q_CORE_EXPORT size_t qHash(const QMimeType &key, size_t seed) noexcept; QExplicitlySharedDataPointer<QMimeTypePrivate> d; }; diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 83873edf6f..fc70ca1386 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -1089,7 +1089,7 @@ QDebug operator<<(QDebug dbg, const QUuid &id) \relates QUuid Returns a hash of the UUID \a uuid, using \a seed to seed the calculation. */ -uint qHash(const QUuid &uuid, uint seed) noexcept +size_t qHash(const QUuid &uuid, size_t seed) noexcept { return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16) ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3]) diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 713ca070c8..bdd74f4b77 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -243,7 +243,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, uint seed = 0) noexcept; +Q_CORE_EXPORT size_t qHash(const QUuid &uuid, size_t seed = 0) noexcept; inline bool operator<=(const QUuid &lhs, const QUuid &rhs) noexcept { return !(rhs < lhs); } diff --git a/src/corelib/serialization/qcborarray.cpp b/src/corelib/serialization/qcborarray.cpp index ca0156e07d..3bb99176af 100644 --- a/src/corelib/serialization/qcborarray.cpp +++ b/src/corelib/serialization/qcborarray.cpp @@ -1200,7 +1200,7 @@ void QCborArray::detach(qsizetype reserved) Returns the offset of this iterator relative to \a other. */ -uint qHash(const QCborArray &array, uint seed) +size_t qHash(const QCborArray &array, size_t seed) { return qHashRange(array.begin(), array.end(), seed); } diff --git a/src/corelib/serialization/qcborarray.h b/src/corelib/serialization/qcborarray.h index fe06b8630f..0438b920ab 100644 --- a/src/corelib/serialization/qcborarray.h +++ b/src/corelib/serialization/qcborarray.h @@ -294,7 +294,7 @@ inline QCborArray QCborValueRef::toArray(const QCborArray &a) const return concrete().toArray(a); } -Q_CORE_EXPORT uint qHash(const QCborArray &array, uint seed = 0); +Q_CORE_EXPORT size_t qHash(const QCborArray &array, size_t seed = 0); #if !defined(QT_NO_DEBUG_STREAM) Q_CORE_EXPORT QDebug operator<<(QDebug, const QCborArray &a); diff --git a/src/corelib/serialization/qcborcommon.h b/src/corelib/serialization/qcborcommon.h index bec46399ce..1497da3d2e 100644 --- a/src/corelib/serialization/qcborcommon.h +++ b/src/corelib/serialization/qcborcommon.h @@ -138,12 +138,12 @@ QDataStream &operator<<(QDataStream &ds, QCborSimpleType st); QDataStream &operator>>(QDataStream &ds, QCborSimpleType &st); #endif -inline uint qHash(QCborSimpleType tag, uint seed = 0) +inline size_t qHash(QCborSimpleType tag, size_t seed = 0) { return qHash(quint8(tag), seed); } -inline uint qHash(QCborTag tag, uint seed = 0) +inline size_t qHash(QCborTag tag, size_t seed = 0) { return qHash(quint64(tag), seed); } diff --git a/src/corelib/serialization/qcbormap.cpp b/src/corelib/serialization/qcbormap.cpp index 4b28ca4a2e..9a8a2c4417 100644 --- a/src/corelib/serialization/qcbormap.cpp +++ b/src/corelib/serialization/qcbormap.cpp @@ -1744,7 +1744,7 @@ void QCborMap::detach(qsizetype reserved) \sa operator+=(), operator-() */ -uint qHash(const QCborMap &map, uint seed) +size_t qHash(const QCborMap &map, size_t seed) { return qHashRange(map.begin(), map.end(), seed); } diff --git a/src/corelib/serialization/qcbormap.h b/src/corelib/serialization/qcbormap.h index 6636ce776a..0609c0a39e 100644 --- a/src/corelib/serialization/qcbormap.h +++ b/src/corelib/serialization/qcbormap.h @@ -350,7 +350,7 @@ inline QCborMap QCborValueRef::toMap(const QCborMap &m) const return concrete().toMap(m); } -Q_CORE_EXPORT uint qHash(const QCborMap &map, uint seed = 0); +Q_CORE_EXPORT size_t qHash(const QCborMap &map, size_t seed = 0); #if !defined(QT_NO_DEBUG_STREAM) Q_CORE_EXPORT QDebug operator<<(QDebug, const QCborMap &m); diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index ddc303e15d..298ebcfd72 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -2921,7 +2921,7 @@ inline QCborMap::QCborMap(QCborContainerPrivate &dd) noexcept { } -uint qHash(const QCborValue &value, uint seed) +size_t qHash(const QCborValue &value, size_t seed) { switch (value.type()) { case QCborValue::Integer: diff --git a/src/corelib/serialization/qcborvalue.h b/src/corelib/serialization/qcborvalue.h index bbe2774e69..9923710eaa 100644 --- a/src/corelib/serialization/qcborvalue.h +++ b/src/corelib/serialization/qcborvalue.h @@ -481,7 +481,7 @@ private: qsizetype i; }; -Q_CORE_EXPORT uint qHash(const QCborValue &value, uint seed = 0); +Q_CORE_EXPORT size_t qHash(const QCborValue &value, size_t seed = 0); #if !defined(QT_NO_DEBUG_STREAM) Q_CORE_EXPORT QDebug operator<<(QDebug, const QCborValue &v); diff --git a/src/corelib/serialization/qjsonarray.cpp b/src/corelib/serialization/qjsonarray.cpp index 05138ad610..98ace021fc 100644 --- a/src/corelib/serialization/qjsonarray.cpp +++ b/src/corelib/serialization/qjsonarray.cpp @@ -1133,7 +1133,7 @@ void QJsonArray::compact() a->compact(a->elements.size()); } -uint qHash(const QJsonArray &array, uint seed) +size_t qHash(const QJsonArray &array, size_t seed) { return qHashRange(array.begin(), array.end(), seed); } diff --git a/src/corelib/serialization/qjsonarray.h b/src/corelib/serialization/qjsonarray.h index 9b7e10766f..d39522bd2f 100644 --- a/src/corelib/serialization/qjsonarray.h +++ b/src/corelib/serialization/qjsonarray.h @@ -252,7 +252,7 @@ private: Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QJsonArray) -Q_CORE_EXPORT uint qHash(const QJsonArray &array, uint seed = 0); +Q_CORE_EXPORT size_t qHash(const QJsonArray &array, size_t seed = 0); #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonArray &); diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index b76e50e2d2..1a85429c82 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -1487,7 +1487,7 @@ void QJsonObject::removeAt(int index) o->removeAt(index); } -uint qHash(const QJsonObject &object, uint seed) +size_t qHash(const QJsonObject &object, size_t seed) { QtPrivate::QHashCombine hash; for (auto it = object.begin(), end = object.end(); it != end; ++it) { diff --git a/src/corelib/serialization/qjsonobject.h b/src/corelib/serialization/qjsonobject.h index c31be0353d..dc449eecf4 100644 --- a/src/corelib/serialization/qjsonobject.h +++ b/src/corelib/serialization/qjsonobject.h @@ -302,7 +302,7 @@ private: Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QJsonObject) -Q_CORE_EXPORT uint qHash(const QJsonObject &object, uint seed = 0); +Q_CORE_EXPORT size_t qHash(const QJsonObject &object, size_t seed = 0); #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonObject &); diff --git a/src/corelib/serialization/qjsonvalue.cpp b/src/corelib/serialization/qjsonvalue.cpp index e9ba176d7f..5eb33bd2a3 100644 --- a/src/corelib/serialization/qjsonvalue.cpp +++ b/src/corelib/serialization/qjsonvalue.cpp @@ -943,7 +943,7 @@ QJsonValue QJsonValueRef::toValue() const return o->valueAt(index); } -uint qHash(const QJsonValue &value, uint seed) +size_t qHash(const QJsonValue &value, size_t seed) { switch (value.type()) { case QJsonValue::Null: diff --git a/src/corelib/serialization/qjsonvalue.h b/src/corelib/serialization/qjsonvalue.h index bd8bf14baf..fa877ff7ee 100644 --- a/src/corelib/serialization/qjsonvalue.h +++ b/src/corelib/serialization/qjsonvalue.h @@ -232,7 +232,7 @@ public: Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QJsonValue) -Q_CORE_EXPORT uint qHash(const QJsonValue &value, uint seed = 0); +Q_CORE_EXPORT size_t qHash(const QJsonValue &value, size_t seed = 0); #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonValue &); diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index f140023e31..7018926bd3 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -216,12 +216,9 @@ public: QPointer<QObject> guard; QObject *obj; QByteArray prop; - // two overloads because friends can't have default arguments - friend uint qHash(const RestorableId &key, uint seed) + friend size_t qHash(const RestorableId &key, size_t seed) noexcept(noexcept(qHash(std::declval<QByteArray>()))) { return qHash(qMakePair(key.obj, key.prop), seed); } - friend uint qHash(const RestorableId &key) noexcept(noexcept(qHash(key, 0U))) - { return qHash(key, 0U); } friend bool operator==(const RestorableId &lhs, const RestorableId &rhs) noexcept { return lhs.obj == rhs.obj && lhs.prop == rhs.prop; } friend bool operator!=(const RestorableId &lhs, const RestorableId &rhs) noexcept diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 52bde98b62..b778316a15 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -5028,7 +5028,7 @@ QByteArray QByteArray::toPercentEncoding(const QByteArray &exclude, const QByteA Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QByteArray::FromBase64Result &key, uint seed) noexcept +size_t qHash(const QByteArray::FromBase64Result &key, size_t seed) noexcept { QtPrivate::QHashCombine hash; seed = hash(seed, key.decoded); diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index d260a9d678..55d4c87e92 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -697,7 +697,7 @@ inline bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray return !operator==(lhs, rhs); } -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QByteArray::FromBase64Result &key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QByteArray::FromBase64Result &key, size_t seed = 0) noexcept; QT_END_NAMESPACE diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 9e3043046d..4af039298f 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -1089,7 +1089,7 @@ bool QLocale::operator!=(const QLocale &other) const Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QLocale &key, uint seed) noexcept +size_t qHash(const QLocale &key, size_t seed) noexcept { QtPrivate::QHashCombine hash; seed = hash(seed, key.d->m_data); diff --git a/src/corelib/text/qlocale.h b/src/corelib/text/qlocale.h index 45e39aa60d..e501a33764 100644 --- a/src/corelib/text/qlocale.h +++ b/src/corelib/text/qlocale.h @@ -59,7 +59,7 @@ class QTextStreamPrivate; class QLocalePrivate; -Q_CORE_EXPORT uint qHash(const QLocale &key, uint seed = 0) noexcept; +Q_CORE_EXPORT size_t qHash(const QLocale &key, size_t seed = 0) noexcept; class Q_CORE_EXPORT QLocale { @@ -1131,7 +1131,7 @@ private: friend class QSystemLocale; friend class QCalendarBackend; friend class QGregorianCalendar; - friend Q_CORE_EXPORT uint qHash(const QLocale &key, uint seed) noexcept; + friend Q_CORE_EXPORT size_t qHash(const QLocale &key, size_t seed) noexcept; QSharedDataPointer<QLocalePrivate> d; }; diff --git a/src/corelib/text/qregexp.cpp b/src/corelib/text/qregexp.cpp index 3b6cdb133a..eac529e5b7 100644 --- a/src/corelib/text/qregexp.cpp +++ b/src/corelib/text/qregexp.cpp @@ -891,7 +891,7 @@ static bool operator==(const QRegExpEngineKey &key1, const QRegExpEngineKey &key && key1.cs == key2.cs; } -static uint qHash(const QRegExpEngineKey &key, uint seed = 0) noexcept +static size_t qHash(const QRegExpEngineKey &key, size_t seed = 0) noexcept { QtPrivate::QHashCombine hash; seed = hash(seed, key.pattern); @@ -4041,7 +4041,7 @@ bool QRegExp::operator==(const QRegExp &rx) const Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QRegExp &key, uint seed) noexcept +size_t qHash(const QRegExp &key, size_t seed) noexcept { QtPrivate::QHashCombine hash; seed = hash(seed, key.priv->engineKey); diff --git a/src/corelib/text/qregexp.h b/src/corelib/text/qregexp.h index 8f6de24c74..b42214f1db 100644 --- a/src/corelib/text/qregexp.h +++ b/src/corelib/text/qregexp.h @@ -53,7 +53,7 @@ struct QRegExpPrivate; class QStringList; class QRegExp; -Q_CORE_EXPORT uint qHash(const QRegExp &key, uint seed = 0) noexcept; +Q_CORE_EXPORT size_t qHash(const QRegExp &key, size_t seed = 0) noexcept; class Q_CORE_EXPORT QRegExp { @@ -110,7 +110,7 @@ public: static QString escape(const QString &str); - friend Q_CORE_EXPORT uint qHash(const QRegExp &key, uint seed) noexcept; + friend Q_CORE_EXPORT size_t qHash(const QRegExp &key, size_t seed) noexcept; private: QRegExpPrivate *priv; diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 6544abb646..77aad5e294 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -1828,7 +1828,7 @@ bool QRegularExpression::operator==(const QRegularExpression &re) const Returns the hash value for \a key, using \a seed to seed the calculation. */ -uint qHash(const QRegularExpression &key, uint seed) noexcept +size_t qHash(const QRegularExpression &key, size_t seed) noexcept { QtPrivate::QHashCombine hash; seed = hash(seed, key.d->pattern); diff --git a/src/corelib/text/qregularexpression.h b/src/corelib/text/qregularexpression.h index 9f618bf7f5..aa6c48bf54 100644 --- a/src/corelib/text/qregularexpression.h +++ b/src/corelib/text/qregularexpression.h @@ -59,7 +59,7 @@ class QRegularExpressionMatchIterator; struct QRegularExpressionPrivate; class QRegularExpression; -Q_CORE_EXPORT uint qHash(const QRegularExpression &key, uint seed = 0) noexcept; +Q_CORE_EXPORT size_t qHash(const QRegularExpression &key, size_t seed = 0) noexcept; class Q_CORE_EXPORT QRegularExpression { @@ -167,7 +167,7 @@ private: friend class QRegularExpressionMatch; friend struct QRegularExpressionMatchPrivate; friend class QRegularExpressionMatchIterator; - friend Q_CORE_EXPORT uint qHash(const QRegularExpression &key, uint seed) noexcept; + friend Q_CORE_EXPORT size_t qHash(const QRegularExpression &key, size_t seed) noexcept; QRegularExpression(QRegularExpressionPrivate &dd); QExplicitlySharedDataPointer<QRegularExpressionPrivate> d; diff --git a/src/corelib/time/qcalendar.cpp b/src/corelib/time/qcalendar.cpp index 02788f5e23..7b50eb008c 100644 --- a/src/corelib/time/qcalendar.cpp +++ b/src/corelib/time/qcalendar.cpp @@ -61,7 +61,7 @@ inline bool operator==(const CalendarName &u, const CalendarName &v) return u.compare(v, Qt::CaseInsensitive) == 0; } -inline uint qHash(const CalendarName &key, uint seed = 0) noexcept +inline size_t qHash(const CalendarName &key, size_t seed = 0) noexcept { return qHash(key.toLower(), seed); } diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 5cd410c0b0..15654117a9 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -5950,13 +5950,13 @@ QDebug operator<<(QDebug dbg, const QDateTime &date) } #endif // debug_stream && datestring -/*! \fn uint qHash(const QDateTime &key, uint seed = 0) +/*! \fn size_t qHash(const QDateTime &key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(const QDateTime &key, uint seed) +size_t qHash(const QDateTime &key, size_t seed) { // Use to toMSecsSinceEpoch instead of individual qHash functions for // QDate/QTime/spec/offset because QDateTime::operator== converts both arguments @@ -5965,24 +5965,24 @@ uint qHash(const QDateTime &key, uint seed) return key.isValid() ? qHash(key.toMSecsSinceEpoch(), seed) : seed; } -/*! \fn uint qHash(QDate key, uint seed = 0) +/*! \fn size_t qHash(QDate key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(QDate key, uint seed) noexcept +size_t qHash(QDate key, size_t seed) noexcept { return qHash(key.toJulianDay(), seed); } -/*! \fn uint qHash(QTime key, uint seed = 0) +/*! \fn size_t qHash(QTime key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(QTime key, uint seed) noexcept +size_t qHash(QTime key, size_t seed) noexcept { return qHash(key.msecsSinceStartOfDay(), seed); } diff --git a/src/corelib/time/qdatetime.h b/src/corelib/time/qdatetime.h index b1a3e0b1d6..52524f70a4 100644 --- a/src/corelib/time/qdatetime.h +++ b/src/corelib/time/qdatetime.h @@ -447,9 +447,9 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &); // QDateTime is not noexcept for now -- to be revised once // timezone and calendaring support is added -Q_CORE_EXPORT uint qHash(const QDateTime &key, uint seed = 0); -Q_CORE_EXPORT uint qHash(QDate key, uint seed = 0) noexcept; -Q_CORE_EXPORT uint qHash(QTime key, uint seed = 0) noexcept; +Q_CORE_EXPORT size_t qHash(const QDateTime &key, size_t seed = 0); +Q_CORE_EXPORT size_t qHash(QDate key, size_t seed = 0) noexcept; +Q_CORE_EXPORT size_t qHash(QTime key, size_t seed = 0) noexcept; QT_END_NAMESPACE diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h index ac3a8771d9..e8ef032c24 100644 --- a/src/corelib/tools/qbitarray.h +++ b/src/corelib/tools/qbitarray.h @@ -50,7 +50,7 @@ class Q_CORE_EXPORT QBitArray { friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QBitArray &); friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QBitArray &); - friend Q_CORE_EXPORT uint qHash(const QBitArray &key, uint seed) noexcept; + friend Q_CORE_EXPORT size_t qHash(const QBitArray &key, size_t seed) noexcept; QByteArray d; public: diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index f053341afd..ab699a7f94 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -210,11 +210,6 @@ static inline uint hash(const uchar *p, size_t len, uint seed) noexcept return h; } -uint qHashBits(const void *p, size_t len, uint seed) noexcept -{ - return hash(static_cast<const uchar*>(p), int(len), seed); -} - static inline uint hash(const QChar *p, size_t len, uint seed) noexcept { uint h = seed; @@ -228,33 +223,38 @@ static inline uint hash(const QChar *p, size_t len, uint seed) noexcept return h; } -uint qHash(const QByteArray &key, uint seed) noexcept +size_t qHashBits(const void *p, size_t size, size_t seed) noexcept +{ + return hash(static_cast<const uchar*>(p), int(size), static_cast<uint>(seed)); +} + + +size_t qHash(const QByteArray &key, size_t seed) noexcept { return hash(reinterpret_cast<const uchar *>(key.constData()), size_t(key.size()), seed); } #if QT_STRINGVIEW_LEVEL < 2 -uint qHash(const QString &key, uint seed) noexcept +size_t qHash(const QString &key, size_t seed) noexcept { return hash(key.unicode(), size_t(key.size()), seed); } -uint qHash(const QStringRef &key, uint seed) noexcept +size_t qHash(const QStringRef &key, size_t seed) noexcept { return hash(key.unicode(), size_t(key.size()), seed); } #endif -uint qHash(QStringView key, uint seed) noexcept +size_t qHash(QStringView key, size_t seed) noexcept { return hash(key.data(), key.size(), seed); } -uint qHash(const QBitArray &bitArray, uint seed) noexcept +size_t qHash(const QBitArray &bitArray, size_t seed) noexcept { int m = bitArray.d.size() - 1; - uint result = hash(reinterpret_cast<const uchar *>(bitArray.d.constData()), - size_t(qMax(0, m)), seed); + size_t result = qHashBits(reinterpret_cast<const uchar *>(bitArray.d.constData()), size_t(qMax(0, m)), seed); // deal with the last 0 to 7 bits manually, because we can't trust that // the padding is initialized to 0 in bitArray.d @@ -264,7 +264,7 @@ uint qHash(const QBitArray &bitArray, uint seed) noexcept return result; } -uint qHash(QLatin1String key, uint seed) noexcept +size_t qHash(QLatin1String key, size_t seed) noexcept { return hash(reinterpret_cast<const uchar *>(key.data()), size_t(key.size()), seed); } @@ -406,7 +406,7 @@ uint qt_hash(QStringView key, uint chained) noexcept } /*! - \fn template <typename T1, typename T2> uint qHash(const QPair<T1, T2> &key, uint seed = 0) + \fn template <typename T1, typename T2> size_t qHash(const QPair<T1, T2> &key, size_t seed = 0) \since 5.0 \relates QHash @@ -416,7 +416,7 @@ uint qt_hash(QStringView key, uint chained) noexcept */ /*! - \fn template <typename T1, typename T2> uint qHash(const std::pair<T1, T2> &key, uint seed = 0) + \fn template <typename T1, typename T2> size_t qHash(const std::pair<T1, T2> &key, size_t seed = 0) \since 5.7 \relates QHash @@ -430,7 +430,7 @@ uint qt_hash(QStringView key, uint chained) noexcept constraints, we cannot change the QPair algorithm to match the std::pair one before Qt 6. */ -/*! \fn template <typename InputIterator> uint qHashRange(InputIterator first, InputIterator last, uint seed = 0) +/*! \fn template <typename InputIterator> size_t qHashRange(InputIterator first, InputIterator last, size_t seed = 0) \relates QHash \since 5.5 @@ -465,7 +465,7 @@ uint qt_hash(QStringView key, uint chained) noexcept \sa qHashBits(), qHashRangeCommutative() */ -/*! \fn template <typename InputIterator> uint qHashRangeCommutative(InputIterator first, InputIterator last, uint seed = 0) +/*! \fn template <typename InputIterator> size_t qHashRangeCommutative(InputIterator first, InputIterator last, size_t seed = 0) \relates QHash \since 5.5 @@ -501,7 +501,7 @@ uint qt_hash(QStringView key, uint chained) noexcept \sa qHashBits(), qHashRange() */ -/*! \fn uint qHashBits(const void *p, size_t len, uint seed = 0) +/*! \fn size_t qHashBits(const void *p, size_t len, size_t seed = 0) \relates QHash \since 5.4 @@ -526,77 +526,77 @@ uint qt_hash(QStringView key, uint chained) noexcept \sa qHashRange(), qHashRangeCommutative() */ -/*! \fn uint qHash(char key, uint seed = 0) +/*! \fn size_t qHash(char key, size_t 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(uchar key, uint seed = 0) +/*! \fn size_t qHash(uchar key, size_t 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(signed char key, uint seed = 0) +/*! \fn size_t qHash(signed char key, size_t 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) +/*! \fn size_t qHash(ushort key, size_t 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) +/*! \fn size_t qHash(short key, size_t 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) +/*! \fn size_t qHash(uint key, size_t 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) +/*! \fn size_t qHash(int key, size_t 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) +/*! \fn size_t qHash(ulong key, size_t 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) +/*! \fn size_t qHash(long key, size_t 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) +/*! \fn size_t qHash(quint64 key, size_t 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) +/*! \fn size_t qHash(qint64 key, size_t seed = 0) \relates QHash \since 5.0 @@ -608,7 +608,7 @@ uint qt_hash(QStringView key, uint chained) noexcept Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(float key, uint seed) noexcept +size_t qHash(float key, size_t seed) noexcept { return key != 0.0f ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ; } @@ -618,7 +618,7 @@ uint qHash(float key, uint seed) noexcept Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(double key, uint seed) noexcept +size_t qHash(double key, size_t seed) noexcept { return key != 0.0 ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ; } @@ -629,62 +629,62 @@ uint qHash(double key, uint seed) noexcept Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(long double key, uint seed) noexcept +size_t qHash(long double key, size_t seed) noexcept { return key != 0.0L ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ; } #endif -/*! \fn uint qHash(const QChar key, uint seed = 0) +/*! \fn size_t qHash(const QChar key, size_t 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) +/*! \fn size_t qHash(const QByteArray &key, size_t 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) +/*! \fn size_t qHash(const QBitArray &key, size_t 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) +/*! \fn size_t qHash(const QString &key, size_t 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) +/*! \fn size_t qHash(const QStringRef &key, size_t 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(QStringView key, uint seed = 0) +/*! \fn size_t qHash(QStringView key, size_t seed = 0) \relates QStringView \since 5.10 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(QLatin1String key, uint seed = 0) +/*! \fn size_t qHash(QLatin1String key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn template <class T> uint qHash(const T *key, uint seed = 0) +/*! \fn template <class T> size_t qHash(const T *key, size_t seed = 0) \relates QHash \since 5.0 @@ -2855,7 +2855,7 @@ uint qHash(long double key, uint seed) noexcept */ /*! - \fn template <class Key, class T> uint qHash(const QHash<Key, T> &key, uint seed = 0) + \fn template <class Key, class T> size_t qHash(const QHash<Key, T> &key, size_t seed = 0) \since 5.8 \relates QHash @@ -2865,7 +2865,7 @@ uint qHash(long double key, uint seed) noexcept */ /*! - \fn template <class Key, class T> uint qHash(const QMultiHash<Key, T> &key, uint seed = 0) + \fn template <class Key, class T> size_t qHash(const QMultiHash<Key, T> &key, size_t seed = 0) \since 5.8 \relates QMultiHash diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index d5d13f7bf3..1d3f84d0ec 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -2011,7 +2011,7 @@ public: #endif // !QT_NO_JAVA_STYLE_ITERATORS template <class Key, class T> -uint qHash(const QHash<Key, T> &key, uint seed = 0) +size_t qHash(const QHash<Key, T> &key, size_t seed = 0) noexcept(noexcept(qHash(std::declval<Key&>())) && noexcept(qHash(std::declval<T&>()))) { QtPrivate::QHashCombineCommutative hash; @@ -2024,7 +2024,7 @@ uint qHash(const QHash<Key, T> &key, uint seed = 0) } template <class Key, class T> -inline uint qHash(const QMultiHash<Key, T> &key, uint seed = 0) +inline size_t qHash(const QMultiHash<Key, T> &key, size_t seed = 0) noexcept(noexcept(qHash(std::declval<Key&>())) && noexcept(qHash(std::declval<T&>()))) { const QHash<Key, T> &key2 = key; diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h index 2e62e93ac4..de3a456f4b 100644 --- a/src/corelib/tools/qhashfunctions.h +++ b/src/corelib/tools/qhashfunctions.h @@ -70,7 +70,7 @@ Q_CORE_EXPORT void qSetGlobalQHashSeed(int newSeed); namespace QHashPrivate { -Q_DECL_CONST_FUNCTION constexpr uint hash(size_t key, uint seed) noexcept +Q_DECL_CONST_FUNCTION constexpr size_t hash(size_t key, size_t seed) noexcept { key ^= seed; if constexpr (sizeof(size_t) == 4) { @@ -86,74 +86,74 @@ Q_DECL_CONST_FUNCTION constexpr uint hash(size_t key, uint seed) noexcept key ^= key >> 32; key *= UINT64_C(0xd6e8feb86659fd93); key ^= key >> 32; - return uint(key); + return key; } } } -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHashBits(const void *p, size_t size, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHashBits(const void *p, size_t size, size_t seed = 0) noexcept; -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(char key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(char key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uchar key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(uchar key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(signed char key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(signed char key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ushort key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(ushort key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(short key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(short key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uint key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(uint key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(int key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(int key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ulong key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(ulong key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(long key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(long key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(quint64 key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(quint64 key, size_t seed = 0) noexcept { if (sizeof(quint64) > sizeof(size_t)) key ^= (key >> 32); return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(qint64 key, uint seed = 0) noexcept { return qHash(quint64(key), seed); } -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(float key, uint seed = 0) noexcept; -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(double key, uint seed = 0) noexcept; +Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(qint64 key, size_t seed = 0) noexcept { return qHash(quint64(key), seed); } +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(float key, size_t seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(double key, size_t seed = 0) noexcept; #if !defined(Q_OS_DARWIN) || defined(Q_CLANG_QDOC) -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(long double key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(long double key, size_t seed = 0) noexcept; #endif -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(const QChar key, uint seed = 0) noexcept { return qHash(key.unicode(), seed); } -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QByteArray &key, uint seed = 0) noexcept; +Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(const QChar key, size_t seed = 0) noexcept { return qHash(key.unicode(), seed); } +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QByteArray &key, size_t seed = 0) noexcept; #if QT_STRINGVIEW_LEVEL < 2 -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QString &key, uint seed = 0) noexcept; -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QStringRef &key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QString &key, size_t seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QStringRef &key, size_t seed = 0) noexcept; #endif -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QStringView key, uint seed = 0) noexcept; -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QBitArray &key, uint seed = 0) noexcept; -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QLatin1String key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QStringView key, size_t seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QBitArray &key, size_t seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QLatin1String key, size_t seed = 0) noexcept; Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(QStringView key, uint chained = 0) noexcept; -Q_DECL_CONST_FUNCTION inline uint qHash(std::nullptr_t, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(std::nullptr_t, size_t seed = 0) noexcept { - return qHash(reinterpret_cast<quintptr>(nullptr), seed); + return seed; } -template <class T> inline uint qHash(const T *key, uint seed = 0) noexcept +template <class T> inline size_t qHash(const T *key, size_t seed = 0) noexcept { return qHash(reinterpret_cast<quintptr>(key), seed); } -template<typename T> inline uint qHash(const T &t, uint seed) +template<typename T> inline size_t qHash(const T &t, size_t seed) noexcept(noexcept(qHash(t))) { return qHash(t) ^ seed; } namespace QtPrivate { struct QHashCombine { - typedef uint result_type; + typedef size_t result_type; template <typename T> - Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const noexcept(noexcept(qHash(t))) + constexpr result_type operator()(size_t seed, const T &t) const noexcept(noexcept(qHash(t))) // combiner taken from N3876 / boost::hash_combine { return seed ^ (qHash(t) + 0x9e3779b9 + (seed << 6) + (seed >> 2)) ; } }; @@ -164,37 +164,38 @@ struct QHashCombineCommutative { // usually what we want: {0,1,3} should hash differently than // {1,3,0}. Except when it isn't (e.g. for QSet and // QHash). Therefore, provide a commutative combiner, too. - typedef uint result_type; + typedef size_t result_type; template <typename T> - Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const noexcept(noexcept(qHash(t))) + constexpr result_type operator()(size_t seed, const T &t) const noexcept(noexcept(qHash(t))) { return seed + qHash(t); } // don't use xor! }; } // namespace QtPrivate template <typename InputIterator> -inline uint qHashRange(InputIterator first, InputIterator last, uint seed = 0) +inline size_t qHashRange(InputIterator first, InputIterator last, size_t seed = 0) noexcept(noexcept(qHash(*first))) // assume iterator operations don't throw { return std::accumulate(first, last, seed, QtPrivate::QHashCombine()); } template <typename InputIterator> -inline uint qHashRangeCommutative(InputIterator first, InputIterator last, uint seed = 0) +inline size_t qHashRangeCommutative(InputIterator first, InputIterator last, size_t seed = 0) noexcept(noexcept(qHash(*first))) // assume iterator operations don't throw { return std::accumulate(first, last, seed, QtPrivate::QHashCombineCommutative()); } -template <typename T1, typename T2> inline uint qHash(const QPair<T1, T2> &key, uint seed = 0) +template <typename T1, typename T2> inline size_t qHash(const QPair<T1, T2> &key, size_t seed = 0) noexcept(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed))) { - uint h1 = qHash(key.first, seed); - uint h2 = qHash(key.second, seed); - return ((h1 << 16) | (h1 >> 16)) ^ h2 ^ seed; + QtPrivate::QHashCombine hash; + seed = hash(seed, key.first); + seed = hash(seed, key.second); + return seed; } -template <typename T1, typename T2> inline uint qHash(const std::pair<T1, T2> &key, uint seed = 0) +template <typename T1, typename T2> inline size_t qHash(const std::pair<T1, T2> &key, size_t seed = 0) noexcept(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed))) { QtPrivate::QHashCombine hash; diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index b631587177..f078e62999 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -230,7 +230,7 @@ QSet(InputIterator, InputIterator) -> QSet<ValueType>; #endif template <typename T> -uint qHash(const QSet<T> &key, uint seed = 0) +size_t qHash(const QSet<T> &key, size_t seed = 0) noexcept(noexcept(qHashRangeCommutative(key.begin(), key.end(), seed))) { return qHashRangeCommutative(key.begin(), key.end(), seed); diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc index 42dd1288ac..eb6b542181 100644 --- a/src/corelib/tools/qset.qdoc +++ b/src/corelib/tools/qset.qdoc @@ -1136,7 +1136,7 @@ */ /*! - \fn template <class T> uint qHash(const QSet<T> &key, uint seed = 0) + \fn template <class T> size_t qHash(const QSet<T> &key, size_t seed = 0) \relates QHash \since 5.5 diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index f123f8e7b9..ef3e689e92 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -305,12 +305,12 @@ Q_INLINE_TEMPLATE void swap(QExplicitlySharedDataPointer<T> &p1, QExplicitlyShar { p1.swap(p2); } template <class T> -Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0) noexcept +Q_INLINE_TEMPLATE size_t qHash(const QSharedDataPointer<T> &ptr, size_t seed = 0) noexcept { return qHash(ptr.data(), seed); } template <class T> -Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0) noexcept +Q_INLINE_TEMPLATE size_t qHash(const QExplicitlySharedDataPointer<T> &ptr, size_t seed = 0) noexcept { return qHash(ptr.data(), seed); } diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 362d57fb9a..b6aad5ff73 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -882,7 +882,7 @@ Q_INLINE_TEMPLATE bool operator<(T *ptr1, const QSharedPointer<X> &ptr2) // qHash // template <class T> -Q_INLINE_TEMPLATE uint qHash(const QSharedPointer<T> &ptr, uint seed = 0) +Q_INLINE_TEMPLATE size_t qHash(const QSharedPointer<T> &ptr, size_t seed = 0) { return QT_PREPEND_NAMESPACE(qHash)(ptr.data(), seed); } diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index a0de6bf2a1..cf5e2ee8c7 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -611,7 +611,7 @@ inline bool operator>=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengt } template <typename T, qsizetype Prealloc> -uint qHash(const QVarLengthArray<T, Prealloc> &key, uint seed = 0) +size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0) noexcept(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) { return qHashRange(key.cbegin(), key.cend(), seed); diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc index a20583c73a..e43d6f152a 100644 --- a/src/corelib/tools/qvarlengtharray.qdoc +++ b/src/corelib/tools/qvarlengtharray.qdoc @@ -903,7 +903,7 @@ */ /*! - \fn template <typename T, qsizetype Prealloc> uint qHash(const QVarLengthArray<T, Prealloc> &key, uint seed = 0) + \fn template <typename T, qsizetype Prealloc> size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0) \relates QVarLengthArray \since 5.14 diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index c4670a0817..f973907714 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -731,7 +731,7 @@ Q_DECLARE_SEQUENTIAL_ITERATOR(Vector) Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(Vector) template <typename T> -uint qHash(const QVector<T> &key, uint seed = 0) +size_t qHash(const QVector<T> &key, size_t seed = 0) noexcept(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) { return qHashRange(key.cbegin(), key.cend(), seed); diff --git a/src/corelib/tools/qvector.qdoc b/src/corelib/tools/qvector.qdoc index daa6ff95e9..cbb118ddb9 100644 --- a/src/corelib/tools/qvector.qdoc +++ b/src/corelib/tools/qvector.qdoc @@ -391,7 +391,7 @@ */ /*! - \fn template <typename T> uint qHash(const QVector<T> &key, uint seed = 0) + \fn template <typename T> size_t qHash(const QVector<T> &key, size_t seed = 0) \since 5.6 \relates QVector diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp index 0883896751..267f618020 100644 --- a/src/corelib/tools/qversionnumber.cpp +++ b/src/corelib/tools/qversionnumber.cpp @@ -541,14 +541,14 @@ QDebug operator<<(QDebug debug, const QVersionNumber &version) #endif /*! - \fn uint qHash(const QVersionNumber &key, uint seed) + \fn size_t qHash(const QVersionNumber &key, size_t seed) \relates QHash \since 5.6 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(const QVersionNumber &key, uint seed) +size_t qHash(const QVersionNumber &key, size_t seed) { QtPrivate::QHashCombine hash; for (int i = 0; i < key.segmentCount(); ++i) diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index f31cdc92a6..c5756bdfb0 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE class QVersionNumber; -Q_CORE_EXPORT uint qHash(const QVersionNumber &key, uint seed = 0); +Q_CORE_EXPORT size_t qHash(const QVersionNumber &key, size_t seed = 0); #ifndef QT_NO_DATASTREAM Q_CORE_EXPORT QDataStream& operator<<(QDataStream &out, const QVersionNumber &version); @@ -283,7 +283,7 @@ private: #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream& operator>>(QDataStream &in, QVersionNumber &version); #endif - friend Q_CORE_EXPORT uint qHash(const QVersionNumber &key, uint seed); + friend Q_CORE_EXPORT size_t qHash(const QVersionNumber &key, size_t seed); }; Q_DECLARE_TYPEINFO(QVersionNumber, Q_MOVABLE_TYPE); |