开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜