Qt 4.8
Classes | Macros | Functions
qhash.h File Reference
#include <QtCore/qatomic.h>
#include <QtCore/qchar.h>
#include <QtCore/qiterator.h>
#include <QtCore/qlist.h>
#include <QtCore/qpair.h>

Go to the source code of this file.

Classes

class  QHash< Key, T >
 The QHash class is a template class that provides a hash-table-based dictionary. More...
 
class  QHash< Key, T >::const_iterator
 The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash. More...
 
class  QHash< Key, T >::iterator
 The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash. More...
 
struct  QHashData
 
struct  QHashData::Node
 
struct  QHashDummyNode< Key, T >
 
struct  QHashDummyValue
 
struct  QHashNode< Key, T >
 
class  QMultiHash< Key, T >
 The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes. More...
 

Macros

#define Q_HASH_DECLARE_INT_NODES(key_type)
 

Functions

bool operator== (const QHashDummyValue &, const QHashDummyValue &)
 
 Q_DECLARE_TYPEINFO (QHashDummyValue, Q_MOVABLE_TYPE|Q_DUMMY_TYPE)
 
 Q_HASH_DECLARE_INT_NODES (int)
 
 Q_HASH_DECLARE_INT_NODES (uint)
 
uint qHash (char key)
 
uint qHash (uchar key)
 
uint qHash (signed char key)
 
uint qHash (ushort key)
 
uint qHash (short key)
 
uint qHash (uint key)
 
uint qHash (int key)
 
uint qHash (ulong key)
 
uint qHash (long key)
 
uint qHash (quint64 key)
 
uint qHash (qint64 key)
 
uint qHash (QChar key)
 
Q_CORE_EXPORT uint qHash (const QByteArray &key)
 Returns the hash value for the key. More...
 
Q_CORE_EXPORT uint qHash (const QString &key)
 
Q_CORE_EXPORT uint qHash (const QStringRef &key)
 
Q_CORE_EXPORT uint qHash (const QBitArray &key)
 
template<class T >
uint qHash (const T *key)
 
template<typename T1 , typename T2 >
uint qHash (const QPair< T1, T2 > &key)
 

Macro Definition Documentation

◆ Q_HASH_DECLARE_INT_NODES

#define Q_HASH_DECLARE_INT_NODES (   key_type)
Value:
template <class T> \
QHashDummyNode *next; \
union { uint h; key_type key; }; \
\
inline QHashDummyNode(key_type /* key0 */) {} \
}; \
\
template <class T> \
QHashNode *next; \
union { uint h; key_type key; }; \
T value; \
\
inline QHashNode(key_type /* key0 */) {} \
inline QHashNode(key_type /* key0 */, const T &value0) : value(value0) {} \
inline bool same_key(uint h0, key_type) { return h0 == h; } \
}
unsigned int uint
Definition: qglobal.h:996
int key

Definition at line 229 of file qhash.h.

Function Documentation

◆ operator==()

bool operator== ( const QHashDummyValue ,
const QHashDummyValue  
)
inline

Definition at line 198 of file qhash.h.

Referenced by QHash< Key, T >::const_iterator::operator-=(), and QHash< QExplicitlySharedDataPointer, QHash >::swap().

199 {
200  return true;
201 }

◆ Q_DECLARE_TYPEINFO()

Q_DECLARE_TYPEINFO ( QHashDummyValue  ,
Q_MOVABLE_TYPE Q_DUMMY_TYPE 
)

Referenced by operator==().

◆ Q_HASH_DECLARE_INT_NODES() [1/2]

Q_HASH_DECLARE_INT_NODES ( int  )

◆ Q_HASH_DECLARE_INT_NODES() [2/2]

Q_HASH_DECLARE_INT_NODES ( uint  )

◆ qHash() [1/18]

uint qHash ( char  key)
related

Definition at line 62 of file qhash.h.

Referenced by QHash< QExplicitlySharedDataPointer, QHash >::findNode().

62 { return uint(key); }
unsigned int uint
Definition: qglobal.h:996
int key

◆ qHash() [2/18]

uint qHash ( uchar  key)
related

Definition at line 63 of file qhash.h.

63 { return uint(key); }
unsigned int uint
Definition: qglobal.h:996
int key

◆ qHash() [3/18]

uint qHash ( signed char  key)
related

Definition at line 64 of file qhash.h.

64 { return uint(key); }
unsigned int uint
Definition: qglobal.h:996
int key

◆ qHash() [4/18]

uint qHash ( ushort  key)
related

Definition at line 65 of file qhash.h.

65 { return uint(key); }
unsigned int uint
Definition: qglobal.h:996
int key

◆ qHash() [5/18]

uint qHash ( short  key)
related

Definition at line 66 of file qhash.h.

66 { return uint(key); }
unsigned int uint
Definition: qglobal.h:996
int key

◆ qHash() [6/18]

uint qHash ( uint  key)
related

Definition at line 67 of file qhash.h.

67 { return key; }
int key

◆ qHash() [7/18]

uint qHash ( int  key)
related

Definition at line 68 of file qhash.h.

68 { return uint(key); }
unsigned int uint
Definition: qglobal.h:996
int key

◆ qHash() [8/18]

uint qHash ( ulong  key)
related

Definition at line 69 of file qhash.h.

70 {
71  if (sizeof(ulong) > sizeof(uint)) {
72  return uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U));
73  } else {
74  return uint(key & (~0U));
75  }
76 }
unsigned int uint
Definition: qglobal.h:996
unsigned long ulong
Definition: qglobal.h:997
int key

◆ qHash() [9/18]

uint qHash ( long  key)
related

Definition at line 77 of file qhash.h.

77 { return qHash(ulong(key)); }
unsigned long ulong
Definition: qglobal.h:997
uint qHash(const QUrl &url)
Definition: qurl.h:285
int key

◆ qHash() [10/18]

uint qHash ( quint64  key)
related

Definition at line 78 of file qhash.h.

79 {
80  if (sizeof(quint64) > sizeof(uint)) {
81  return uint(((key >> (8 * sizeof(uint) - 1)) ^ key) & (~0U));
82  } else {
83  return uint(key & (~0U));
84  }
85 }
unsigned __int64 quint64
Definition: qglobal.h:943
unsigned int uint
Definition: qglobal.h:996
int key

◆ qHash() [11/18]

uint qHash ( qint64  key)
related

Definition at line 86 of file qhash.h.

86 { return qHash(quint64(key)); }
unsigned __int64 quint64
Definition: qglobal.h:943
uint qHash(const QUrl &url)
Definition: qurl.h:285
int key

◆ qHash() [12/18]

uint qHash ( QChar  key)
related

Definition at line 87 of file qhash.h.

87 { return qHash(key.unicode()); }
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
uint qHash(const QUrl &url)
Definition: qurl.h:285

◆ qHash() [13/18]

Q_CORE_EXPORT uint qHash ( const QByteArray key)

Returns the hash value for the key.

Definition at line 92 of file qhash.cpp.

93 {
94  return hash(reinterpret_cast<const uchar *>(key.constData()), key.size());
95 }
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ qHash() [14/18]

Q_CORE_EXPORT uint qHash ( const QString key)
related

Definition at line 97 of file qhash.cpp.

98 {
99  return hash(key.unicode(), key.size());
100 }
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706

◆ qHash() [15/18]

Q_CORE_EXPORT uint qHash ( const QStringRef key)

Definition at line 102 of file qhash.cpp.

103 {
104  return hash(key.unicode(), key.size());
105 }
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
const QChar * unicode() const
Returns a Unicode representation of the string reference.
Definition: qstring.h:1153

◆ qHash() [16/18]

Q_CORE_EXPORT uint qHash ( const QBitArray key)
related

Definition at line 107 of file qhash.cpp.

108 {
109  int m = bitArray.d.size() - 1;
110  uint result = hash(reinterpret_cast<const uchar *>(bitArray.d.constData()), qMax(0, m));
111 
112  // deal with the last 0 to 7 bits manually, because we can't trust that
113  // the padding is initialized to 0 in bitArray.d
114  int n = bitArray.size();
115  if (n & 0x7)
116  result = ((result << 4) + bitArray.d.at(m)) & ((1 << n) - 1);
117  return result;
118 }
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
unsigned int uint
Definition: qglobal.h:996

◆ qHash() [17/18]

template<class T >
uint qHash ( const T *  key)
related

Definition at line 97 of file qhash.h.

98 {
99  return qHash(reinterpret_cast<quintptr>(key));
100 }
uint qHash(const QUrl &url)
Definition: qurl.h:285
int key

◆ qHash() [18/18]

template<typename T1 , typename T2 >
uint qHash ( const QPair< T1, T2 > &  key)
related

Definition at line 105 of file qhash.h.

106 {
107  uint h1 = qHash(key.first);
108  uint h2 = qHash(key.second);
109  return ((h1 << 16) | (h1 >> 16)) ^ h2;
110 }
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66
unsigned int uint
Definition: qglobal.h:996
uint qHash(const QUrl &url)
Definition: qurl.h:285