-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
Labels
wontfixAs designed, Not worth the effortAs designed, Not worth the effort
Description
Hello,
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)
import com.google.common.hash.Hashing
import com.sangupta.murmur.Murmur3
import org.junit.Test
import java.nio.ByteBuffer
import java.util.*
import kotlin.test.assertTrue
private const val SEED = 42
class Murmur3Test {
@Test
fun murmur32shouldCorrespondToGuavaHashes() {
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
fun murmur128shouldCorrespondToGuavaHashes() {
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()
}
ov7a
Metadata
Metadata
Assignees
Labels
wontfixAs designed, Not worth the effortAs designed, Not worth the effort