0

I am confused with how should i call MurmurHash3_x86_128() with integer key value or is it even possible ? The murmurhash3 code can be found https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp. Method definition is given below.

void MurmurHash3_x86_128 ( const void * key, const int len,
                   uint32_t seed, void * out )

I am hashing integer value with len as 1 . Is it correct or wrong ?

int main()
{
uint64_t seed = 100;
int p = 500;  // key to hash

uint64_t hash_otpt[2]= {0};

const int *key = &p;
MurmurHash3_x64_128(key, 1, seed, hash_otpt); // 0xb6d99cf8
cout  << *hash_otpt << endl;

}
rombi
  • 199
  • 3
  • 22

1 Answers1

1

You are passing key, which is a pointer to (const) int, so you should be passing sizeof(int) as the length.

Passing 1 would only work in case int is 1 byte wide on your platform, which is rarely the case.

Banex
  • 2,890
  • 3
  • 28
  • 38
  • Passing 1,2,3 ....100 values is all working. It is not throwing any error. – rombi Nov 20 '16 at 10:23
  • @rombi is it producing the expected result though? I would bet there is undefined behaviour happening instead. – Banex Nov 20 '16 at 10:26