Skip to content

Consistent result with Guava's implementation #21

@roberterdin

Description

@roberterdin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions