murmur3 icon indicating copy to clipboard operation
murmur3 copied to clipboard

Consistent result with Guava's implementation

Open roberterdin opened this issue 6 years ago • 0 comments

I created a function to create a hash string that is consistent with Guava's implementation. Happy to submit a PR for the README since this might be a fairly common use case.

var hexDigits = []byte("0123456789abcdef")
func guavaHash(h1, h2 uint64) string {
	buf := new(bytes.Buffer)
	binary.Write(buf, binary.LittleEndian, h1)
	binary.Write(buf, binary.LittleEndian, h2)
	var result []byte
	for _, curr := range buf.Bytes() {
		result = append(result, hexDigits[(curr>>4)&0xf])
		result = append(result, hexDigits[curr&0xf])
	}
	return string(result)
}

Originally wanted to do a BigInt version as well but since bytes are signed Java and unsigned in Go I passed on that exercise ;)

roberterdin avatar Mar 29 '18 14:03 roberterdin