0

From the C++ standard, the hash function std::tr1::hash computes hash values whose range is 64-bits (correct me if i'm wrong). But out of curiosity, are there any mechanisms that generate hash values with range greater than 64-bit. My question may look weird as the entire memory we use is within 64-bit range, but I would like to know how would we compute a hash value of (let's say) size 80-bit?

EDIT : My bad, I assumed 64-bit implementations.

annunarcist
  • 1,637
  • 3
  • 20
  • 42
  • You have to define your own hash number types (with 80 bits) and your own hash functions. I am not sure that C++11 gives 64 bits hashes on 32 bits implementations. Look also into [cryptographic hash functions](http://en.wikipedia.org/wiki/Cryptographic_hash_function) like MD5 or SHA1 – Basile Starynkevitch Oct 21 '13 at 18:42
  • Yes cryptographic hash functions does the job, but aren't there any non-crypto hash functions (and also standardized) that can do the work? – annunarcist Oct 21 '13 at 18:55
  • You should explain why do you want large hashes... What for? Please explain why a `size_t` hash don't fit your needs! – Basile Starynkevitch Oct 21 '13 at 19:10
  • so my key type is unsigned char array which itself is the output of a cryptographic function. And i want to avoid calling the non-crypto hash function again (which is redundant in this case). – annunarcist Oct 21 '13 at 20:00

1 Answers1

3

The various hash functions in C++11 (which I suppose corresponds to TR1) compute hash values into a size_t, the size of which depends on the implementation (but will be 32 bits for a 32 bit build, and 64 bits for a 64 bit build). If you need a hash with a larger size, then you'll have to calculate it yourself; you may even have to define a larger integral type to support calculating it. (You can't return an 80 bit hash code in a size_t if the size_t is only 64 bits.)

James Kanze
  • 150,581
  • 18
  • 184
  • 329