You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My understanding is that Murmur3.hash_x64_128 (of this project) should return the same result (in bytes) as Hasing.murmur3_128().hashBytes (of guava library).
But It doesn't. May I ask if it is expected to be different and why?
Here is my code, just in case I made an obvious mistake you could point out. (the code is written Kotlin, but should be easily understandable)
importcom.google.common.hash.Hashingimportcom.sangupta.murmur.Murmur3importorg.junit.Testimportjava.nio.ByteBufferimportjava.util.*importkotlin.test.assertTrueprivateconstvalSEED=42classMurmur3Test {
@Test
funmurmur32shouldCorrespondToGuavaHashes() {
val guava =Hashing.murmur3_32(SEED)
repeat(1000) {
val data =UUID.randomUUID().toByteArray()
val guavaResult = guava.hashBytes(data).asBytes()
val murmurResult =Murmur3.hash_x86_32(data, 16, SEED.toLong()).asBytes()
assertTrue(Arrays.equals(guavaResult, murmurResult))
}
}
@Test
funmurmur128shouldCorrespondToGuavaHashes() {
val guava =Hashing.murmur3_128(SEED)
repeat(1000) {
val data =UUID.randomUUID().toByteArray()
val guavaResult = guava.hashBytes(data).asBytes()
val murmurResult =Murmur3.hash_x64_128(data, 16, SEED.toLong()).asBytes()
assertTrue(Arrays.equals(guavaResult, murmurResult))
}
}
}
fun UUID.toByteArray(): ByteArray {
val buffer =ByteBuffer.allocate(16)
buffer.putLong(mostSignificantBits)
buffer.putLong(leastSignificantBits)
return buffer.array()
}
fun LongArray.asBytes(): ByteArray {
val buffer =ByteBuffer.allocate(size *8)
forEach { buffer.putLong(it) }
return buffer.array()
}
fun Long.asBytes(): ByteArray {
val buffer =ByteBuffer.allocate(8)
buffer.putLong(this)
return buffer.array()
}
The text was updated successfully, but these errors were encountered:
Hi @jcornaz - I coded this library using the C++ generated hashes and confirmed that they were the same. It has been quite a long time and I would need some time to debug this issue. My bad on noticing it this late.
The long hash is the same when computed in value (as long) between both Guava and Murmur. I have added documentation on how to convert long to byte[] in both big-endian and little-endian format (refer 56545af).
Hello,
My understanding is that
Murmur3.hash_x64_128
(of this project) should return the same result (in bytes) asHasing.murmur3_128().hashBytes
(of guava library).But It doesn't. May I ask if it is expected to be different and why?
Here is my code, just in case I made an obvious mistake you could point out. (the code is written Kotlin, but should be easily understandable)
The text was updated successfully, but these errors were encountered: