Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent result with Guava's implementation #21

Open
roberterdin opened this issue Mar 29, 2018 · 0 comments
Open

Consistent result with Guava's implementation #21

roberterdin opened this issue Mar 29, 2018 · 0 comments

Comments

@roberterdin
Copy link

roberterdin commented Mar 29, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant