PDA

View Full Version : How does QString::qHash() work?



Morea
7th September 2009, 09:04
How does Qt calculate a hash value for a string?

Does anyone here know that?

nish
7th September 2009, 09:19
are we talking about QCryptographicHash ?
coz qHash is used for a different purpose i think.

Morea
7th September 2009, 09:31
I'm talking about the hashvalue that is calculated for a QString when inserted into a QHash<QString, some_type>

nish
7th September 2009, 09:36
well. then you can just take a look at the qt sources for qHash function..

wysota
7th September 2009, 10:17
How does Qt calculate a hash value for a string?


are we talking about QCryptographicHash ?

The principle is exactly the same, except that cryptographic hash should have a larger number of possible results (value space).

An easy (although completely useless) qHash implementation would be to sum the ascii values of all characters in the string and return that as a value (normalized to the value space).