Different values on each hashing approach
can someone please tell me what i'm doing wrong? i'm trying to hash a value with murmurhash, but i get different values every time:
std::string str = "some test string";
char out[32];
Murmu开发者_如何学CrHash3_x86_32(str.c_str(), str.length(), 0, out);
unsigned int hash = reinterpret_cast<unsigned int>(out);
The variable out
is of type char []
, or array of char
. This acts as a pointer to char
in most contexts. Here, you're casting the pointer value, not the pointed-to contents.
Also, I don't know the MurmurHash API, but the array out
is 32 bytes. You're attempting to cast it to a 32 bit integer (assuming integers are 32-bit on your platform).
It looks to me like MurmurHash3_x86_32
is returning a 32 bits hash value. But you're giving it a 32 bytes output parameter.
You could simply:
std::string str = "some test string";
unsigned int hash;
MurmurHash3_x86_32(str.c_str(), str.length(), 0, &hash);
精彩评论