Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qhashfunctions.h File Reference

(7a6ecc3e5d4d55709508d6c93414b4af57575a4c)

#include <QtCore/qstring.h>
#include <QtCore/qstringfwd.h>
#include <numeric>
#include <functional>
#include <utility>
+ Include dependency graph for qhashfunctions.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  QHashSeed
 \inmodule QtCore More...
 
struct  QHashHeterogeneousSearch< Key, T >
 
struct  QHashHeterogeneousSearch< QString, QStringView >
 
struct  QHashHeterogeneousSearch< QStringView, QString >
 
struct  QHashHeterogeneousSearch< QByteArray, QByteArrayView >
 
struct  QHashHeterogeneousSearch< QByteArrayView, QByteArray >
 
struct  QHashHeterogeneousSearch< QString, QLatin1StringView >
 
struct  QHashHeterogeneousSearch< QStringView, QLatin1StringView >
 
struct  QHashHeterogeneousSearch< QLatin1StringView, QString >
 
struct  QHashHeterogeneousSearch< QLatin1StringView, QStringView >
 
struct  QHashPrivate::detail::is_equality_comparable_with< T, U, typename >
 
struct  QHashPrivate::detail::is_equality_comparable_with< T, U, std::void_t< decltype(bool(std::declval< T >()==std::declval< U >())), decltype(bool(std::declval< U >()==std::declval< T >())), decltype(bool(std::declval< T >() !=std::declval< U >())), decltype(bool(std::declval< U >() !=std::declval< T >())) > >
 
struct  QHashPrivate::HeterogeneouslySearchableWithHelper< Key, T >
 
struct  QtPrivate::QHashCombine
 
struct  QtPrivate::QHashCombineCommutative
 
struct  QtPrivate::QNothrowHashable< T, Enable >
 
struct  QtPrivate::QNothrowHashable< T, std::enable_if_t< QNothrowHashableHelper_v< T > > >
 

Namespaces

namespace  QHashPrivate
 
namespace  QHashPrivate::detail
 
namespace  QtPrivate
 \macro QT_NO_KEYWORDS >
 

Macros

#define QT_MK_QHASH_COMPAT(X)
 
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH(Class, Arguments)
 
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF(Class)
 
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_VALUE(Class)
 

Typedefs

template<typename Key , typename T >
using QHashPrivate::HeterogeneouslySearchableWith
 
template<typename Key , typename K >
using QHashPrivate::if_heterogeneously_searchable_with
 
template<typename... T>
using QtPrivate::QHashMultiReturnType
 

Functions

Q_DECL_CONST_FUNCTION constexpr size_t QHashPrivate::hash (size_t key, size_t seed) noexcept
 
template<typename T1 , typename T2 >
static constexpr bool QHashPrivate::noexceptPairHash ()
 
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHashBits (const void *p, size_t size, size_t seed=0) noexcept
 
template<typename T1 , typename T2 >
size_t qHash (const std::pair< T1, T2 > &key, size_t seed=0) noexcept(QHashPrivate::noexceptPairHash< T1, T2 >())
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (char key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (uchar key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (signed char key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (ushort key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (short key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (uint key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (int key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (ulong key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (long key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (quint64 key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (qint64 key, size_t seed=0) noexcept
 
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
 
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash (long double key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (wchar_t key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (char16_t key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (char32_t key, size_t seed=0) noexcept
 
template<class T >
size_t qHash (const T *key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (std::nullptr_t, size_t seed=0) noexcept
 
template<class Enum , std::enable_if_t< std::is_enum_v< Enum >, bool > = true>
Q_DECL_CONST_FUNCTION constexpr size_t qHash (Enum e, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (const QChar key, size_t seed=0) noexcept
 
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash (QByteArrayView key, size_t seed=0) noexcept
 
Q_DECL_PURE_FUNCTION size_t qHash (const QByteArray &key, size_t seed=0 QT6_DECL_NEW_OVERLOAD_TAIL) noexcept
 
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash (QStringView key, size_t seed=0) noexcept
 
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 QBitArray &key, size_t seed=0)
 
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash (QLatin1StringView key, size_t seed=0) noexcept
 
Q_DECL_CONST_FUNCTION constexpr size_t qHash (QKeyCombination key, size_t seed=0) noexcept
 
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash (QStringView key, uint chained=0) noexcept
 
template<typename Enum >
Q_DECL_CONST_FUNCTION constexpr size_t qHash (QFlags< Enum > flags, size_t seed=0) noexcept
 
template<typename T >
bool qHashEquals (const T &a, const T &b)
 
template<typename T1 , typename T2 , QHashPrivate::if_heterogeneously_searchable_with< T1, T2 > = true>
bool qHashEquals (const T1 &a, const T2 &b)
 
template<typename... T>
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti (size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
 
template<typename... T>
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMultiCommutative (size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
 
template<typename InputIterator >
size_t qHashRange (InputIterator first, InputIterator last, size_t seed=0) noexcept(noexcept(qHash(*first)))
 
template<typename InputIterator >
size_t qHashRangeCommutative (InputIterator first, InputIterator last, size_t seed=0) noexcept(noexcept(qHash(*first)))
 

Variables

template<typename T >
constexpr bool QtPrivate::QNothrowHashableHelper_v = noexcept(qHash(std::declval<const T &>()))
 
template<typename T >
constexpr bool QtPrivate::QNothrowHashable_v = QNothrowHashable<T>::value
 

Macro Definition Documentation

◆ QT_MK_QHASH_COMPAT

#define QT_MK_QHASH_COMPAT ( X)
Value:
template <typename T, std::enable_if_t<std::is_same_v<T, X>, bool> = true> \
constexpr size_t qHash(T key, size_t seed = 0) noexcept \
/* QHashPrivate::hash() xors before mixing, while 1-to-2-arg adapter xors after */ \
{ return QHashPrivate::hash(size_t(key), 0 QT7_ONLY(+ seed)) QT6_ONLY(^ seed); } \
/* end */
Q_DECL_CONST_FUNCTION constexpr size_t hash(size_t key, size_t seed) noexcept
size_t qHash(const std::pair< T1, T2 > &key, size_t seed=0) noexcept(QHashPrivate::noexceptPairHash< T1, T2 >())
GLuint64 key
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
QT_BEGIN_NAMESPACE class QT6_ONLY(Q_CORE_EXPORT) QReadWriteLock

Definition at line 97 of file qhashfunctions.h.

◆ QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH

#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH ( Class,
Arguments )
Value:
QT_BEGIN_INCLUDE_NAMESPACE \
namespace std { \
template <> \
struct hash< QT_PREPEND_NAMESPACE(Class) > { \
using argument_type = QT_PREPEND_NAMESPACE(Class); \
using result_type = size_t; \
size_t operator()(Arguments s) const \
QtPrivate::QNothrowHashable_v)<argument_type>) \
{ \
/* this seeds qHash with the result of */ \
/* std::hash applied to an int, to reap */ \
/* any protection against predictable hash */ \
/* values the std implementation may provide */ \
return qHash(s, qHash(std::hash<int>{}(0))); \
} \
}; \
} \
/*end*/
QHash< int, QWidget * > hash
[35multi]
constexpr bool QNothrowHashable_v
size_t qHash(const QList< T > &key, size_t seed=0) noexcept(noexcept(qHashRange(key.cbegin(), key.cend(), seed)))
Definition qlist.h:1002
GLdouble s
[6]
Definition qopenglext.h:235
#define QT_END_INCLUDE_NAMESPACE
QT_END_NAMESPACE typedef QT_PREPEND_NAMESPACE(quintptr) WId

Definition at line 401 of file qhashfunctions.h.

◆ QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF

#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF ( Class)
Value:
QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH(Class, const argument_type &)
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH(Class, Arguments)

Definition at line 424 of file qhashfunctions.h.

◆ QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_VALUE

#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_VALUE ( Class)
Value:

Definition at line 426 of file qhashfunctions.h.

Function Documentation

◆ qHash() [1/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( char key,
size_t seed = 0 )
related

Definition at line 104 of file qhashfunctions.h.

◆ qHash() [2/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( char16_t key,
size_t seed = 0 )
related

Definition at line 174 of file qhashfunctions.h.

◆ qHash() [3/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( char32_t key,
size_t seed = 0 )
related

Definition at line 176 of file qhashfunctions.h.

◆ qHash() [4/30]

size_t qHash ( const QBitArray & key,
size_t seed = 0 )
related

Definition at line 886 of file qhash.cpp.

◆ qHash() [5/30]

Q_DECL_PURE_FUNCTION size_t qHash ( const QByteArray & key,
size_t seed = QT6_DECL_NEW_OVERLOAD_TAIL )
related

Definition at line 202 of file qhashfunctions.h.

◆ qHash() [6/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( const QChar key,
size_t seed = 0 )
related

Definition at line 195 of file qhashfunctions.h.

◆ qHash() [7/30]

Q_DECL_PURE_FUNCTION size_t qHash ( const QString & key,
size_t seed = 0 )
related

Definition at line 208 of file qhashfunctions.h.

◆ qHash() [8/30]

template<typename T1 , typename T2 >
size_t qHash ( const std::pair< T1, T2 > & key,
size_t seed = 0 )
related

Definition at line 395 of file qhashfunctions.h.

◆ qHash() [9/30]

template<class T >
size_t qHash ( const T * key,
size_t seed = 0 )
related

Definition at line 182 of file qhashfunctions.h.

◆ qHash() [10/30]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash ( double key,
size_t seed = 0 )
related

◆ qHash() [11/30]

template<class Enum , std::enable_if_t< std::is_enum_v< Enum >, bool > = true>
Q_DECL_CONST_FUNCTION constexpr size_t qHash ( Enum e,
size_t seed = 0 )
inlineconstexprnoexcept

Definition at line 191 of file qhashfunctions.h.

◆ qHash() [12/30]

Q_DECL_CONST_FUNCTION size_t qHash ( float key,
size_t seed = 0 )
related

Definition at line 162 of file qhashfunctions.h.

◆ qHash() [13/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( int key,
size_t seed = 0 )
related

Definition at line 116 of file qhashfunctions.h.

◆ qHash() [14/30]

Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash ( long double key,
size_t seed = 0 )
related

◆ qHash() [15/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( long key,
size_t seed = 0 )
related

Definition at line 120 of file qhashfunctions.h.

◆ qHash() [16/30]

size_t qHash ( QByteArrayView key,
size_t seed = 0 )
noexcept

Definition at line 875 of file qhash.cpp.

◆ qHash() [17/30]

template<typename Enum >
Q_DECL_CONST_FUNCTION constexpr size_t qHash ( QFlags< Enum > flags,
size_t seed = 0 )
inlineconstexprnoexcept

Definition at line 219 of file qhashfunctions.h.

◆ qHash() [18/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( qint64 key,
size_t seed = 0 )
related

Definition at line 129 of file qhashfunctions.h.

◆ qHash() [19/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( QKeyCombination key,
size_t seed = 0 )
inlineconstexprnoexcept

Definition at line 214 of file qhashfunctions.h.

◆ qHash() [20/30]

size_t qHash ( QLatin1StringView key,
size_t seed = 0 )
related

Definition at line 900 of file qhash.cpp.

◆ qHash() [21/30]

size_t qHash ( QStringView key,
size_t seed = 0 )
related

Definition at line 880 of file qhash.cpp.

◆ qHash() [22/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( quint64 key,
size_t seed = 0 )
related

Definition at line 123 of file qhashfunctions.h.

◆ qHash() [23/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( short key,
size_t seed = 0 )
related

Definition at line 112 of file qhashfunctions.h.

◆ qHash() [24/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( signed char key,
size_t seed = 0 )
related

Definition at line 108 of file qhashfunctions.h.

◆ qHash() [25/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( std::nullptr_t ,
size_t seed = 0 )
related

Definition at line 186 of file qhashfunctions.h.

◆ qHash() [26/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( uchar key,
size_t seed = 0 )
related

Definition at line 106 of file qhashfunctions.h.

◆ qHash() [27/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( uint key,
size_t seed = 0 )
related

Definition at line 114 of file qhashfunctions.h.

◆ qHash() [28/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( ulong key,
size_t seed = 0 )
related

Definition at line 118 of file qhashfunctions.h.

◆ qHash() [29/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( ushort key,
size_t seed = 0 )
related

Definition at line 110 of file qhashfunctions.h.

◆ qHash() [30/30]

Q_DECL_CONST_FUNCTION constexpr size_t qHash ( wchar_t key,
size_t seed = 0 )
related

Definition at line 172 of file qhashfunctions.h.

◆ qHashBits()

size_t qHashBits ( const void * p,
size_t size,
size_t seed = 0 )
related

Definition at line 850 of file qhash.cpp.

◆ qHashEquals() [1/2]

template<typename T >
bool qHashEquals ( const T & a,
const T & b )
related

Definition at line 287 of file qhashfunctions.h.

◆ qHashEquals() [2/2]

template<typename T1 , typename T2 , QHashPrivate::if_heterogeneously_searchable_with< T1, T2 > = true>
bool qHashEquals ( const T1 & a,
const T2 & b )

Definition at line 293 of file qhashfunctions.h.

◆ qHashMulti()

template<typename... T>
QtPrivate::QHashMultiReturnType< T... > qHashMulti ( size_t seed,
const T &... args )
related

Definition at line 352 of file qhashfunctions.h.

◆ qHashMultiCommutative()

template<typename... T>
QtPrivate::QHashMultiReturnType< T... > qHashMultiCommutative ( size_t seed,
const T &... args )
related

Definition at line 366 of file qhashfunctions.h.

◆ qHashRange()

template<typename InputIterator >
size_t qHashRange ( InputIterator first,
InputIterator last,
size_t seed = 0 )
related

Definition at line 374 of file qhashfunctions.h.

◆ qHashRangeCommutative()

template<typename InputIterator >
size_t qHashRangeCommutative ( InputIterator first,
InputIterator last,
size_t seed = 0 )
related

Definition at line 381 of file qhashfunctions.h.

◆ qt_hash()

uint qt_hash ( QStringView key,
uint chained )
noexcept

Private copy of the implementation of the Qt 4 qHash algorithm for strings, (that is, QChar-based arrays, so all QString-like classes), to be used wherever the result is somehow stored or reused across multiple Qt versions. The public qHash implementation can change at any time, therefore one must not rely on the fact that it will always give the same results.

The qt_hash functions must never change their results.

This function can hash discontiguous memory by invoking it on each chunk, passing the previous's result in the next call's chained argument.

Definition at line 1086 of file qhash.cpp.