Qt 4.8
Functions | Variables
qhash.cpp File Reference
#include "qhash.h"
#include <qbitarray.h>
#include <qstring.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

static int countBits (int hint)
 
static uint hash (const uchar *p, int n)
 
static uint hash (const QChar *p, int n)
 
static int primeForNumBits (int numBits)
 
uint qHash (const QByteArray &key)
 Returns the hash value for the key. More...
 
uint qHash (const QString &key)
 
uint qHash (const QStringRef &key)
 
uint qHash (const QBitArray &bitArray)
 

Variables

const int MinNumBits = 4
 
static const uchar prime_deltas []
 

Function Documentation

◆ countBits()

static int countBits ( int  hint)
static

Definition at line 144 of file qhash.cpp.

Referenced by QHashData::rehash().

145 {
146  int numBits = 0;
147  int bits = hint;
148 
149  while (bits > 1) {
150  bits >>= 1;
151  numBits++;
152  }
153 
154  if (numBits >= (int)sizeof(prime_deltas)) {
155  numBits = sizeof(prime_deltas) - 1;
156  } else if (primeForNumBits(numBits) < hint) {
157  ++numBits;
158  }
159  return numBits;
160 }
static const uchar prime_deltas[]
Definition: qhash.cpp:130
static int primeForNumBits(int numBits)
Definition: qhash.cpp:135

◆ hash() [1/2]

static uint hash ( const uchar p,
int  n 
)
static

Definition at line 68 of file qhash.cpp.

Referenced by QPatternist::XsdStateMachine< XsdSchemaToken::NodeName >::addTransition(), QMetaObject::changeGuard(), cleanup_cmaps(), QObjectPrivate::clearGuards(), convert_RGB_to_Indexed8(), digestMd5ResponseHelper(), QTranslatorPrivate::do_translate(), QResourceRoot::findNode(), QResourceRoot::findOffset(), QApplication::font(), QGLMaskTextureCache::getMask(), QPatternist::XsdParticleChecker::hasDuplicatedElements(), hasDuplicatedElementsInternal(), QDeclarativeDebugService::idForObject(), internalParticleLookupMap(), QDeclarativeDebugService::objectForId(), operator<<(), QProcessEnvironmentPrivate::OrderedMutexLocker::OrderedMutexLocker(), QApplication::palette(), QXmlStreamReaderPrivate::parse(), qEncodeHmacMd5(), qHash(), qStringFromUcs2Le(), qt_CoCreateGuid(), qt_delete_glyph_hash(), qt_fallback_font_family(), qt_gl_choose_cmap(), qt_transparent_pixel(), qt_x11_set_fallback_font_family(), QVariant::QVariant(), QMetaObject::removeGuard(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), QTextControl::setExtraSelections(), QApplication::setFont(), QApplicationPrivate::setPalette_helper(), QPatternist::XsdSchemaContext::setupBuiltinTypesFacetList(), QNetworkDiskCachePrivate::uniqueFileName(), unregWinClasses(), QPropertyAnimation::updateState(), QPatternist::TokenLookup::value(), and QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue().

69 {
70  uint h = 0;
71 
72  while (n--) {
73  h = (h << 4) + *p++;
74  h ^= (h & 0xf0000000) >> 23;
75  h &= 0x0fffffff;
76  }
77  return h;
78 }
unsigned int uint
Definition: qglobal.h:996

◆ hash() [2/2]

static uint hash ( const QChar p,
int  n 
)
static

Definition at line 80 of file qhash.cpp.

81 {
82  uint h = 0;
83 
84  while (n--) {
85  h = (h << 4) + (*p++).unicode();
86  h ^= (h & 0xf0000000) >> 23;
87  h &= 0x0fffffff;
88  }
89  return h;
90 }
unsigned int uint
Definition: qglobal.h:996

◆ primeForNumBits()

static int primeForNumBits ( int  numBits)
inlinestatic

Definition at line 135 of file qhash.cpp.

Referenced by countBits(), and QHashData::rehash().

136 {
137  return (1 << numBits) + prime_deltas[numBits];
138 }
static const uchar prime_deltas[]
Definition: qhash.cpp:130

◆ qHash() [1/4]

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() [2/4]

uint qHash ( const QString key)
related

Definition at line 97 of file qhash.cpp.

Referenced by qHash().

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() [3/4]

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() [4/4]

uint qHash ( const QBitArray bitArray)
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
QByteArray d
Definition: qbitarray.h:59
unsigned int uint
Definition: qglobal.h:996
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
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
int size() const
Returns the number of bits stored in the bit array.
Definition: qbitarray.h:73

Variable Documentation

◆ MinNumBits

const int MinNumBits = 4

Definition at line 166 of file qhash.cpp.

Referenced by QHashData::rehash().

◆ prime_deltas

const uchar prime_deltas[]
static
Initial value:
= {
0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 9, 25, 3,
1, 21, 3, 21, 7, 15, 9, 5, 3, 29, 15, 0, 0, 0, 0, 0
}

Definition at line 130 of file qhash.cpp.

Referenced by countBits(), and primeForNumBits().