Created
April 4, 2023 13:09
-
-
Save hajimes/b174e3cd7b0d0c14be97aa39010f2932 to your computer and use it in GitHub Desktop.
(A part of) a MurmurHash3 murmur128 Go implementation whose result is compatible with C++ (original) and Python versions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This gist is distributed under {public domain, CC0, <some OSI-approved license> Copyright (c) 2023 Hajime Senuma}. | |
// Choose what you want to use. | |
// See | |
// https://github.com/hajimes/mmh3/issues/46 | |
// https://stackoverflow.com/questions/75921577/murmur3-hash-compatibility-between-go-and-python | |
package main | |
import "fmt" | |
// Returns the C MurmurHash3_x64_128-compliant byte sequence (on little-endian machines) | |
// of the result of murmur3.Sum128 or murmur3.Sum128WithSeed | |
func SumLittleEndian(h1, h2 uint64) []byte { | |
var b []byte | |
return append(b, | |
byte(h1), byte(h1>>8), byte(h1>>16), byte(h1>>24), byte(h1>>32), | |
byte(h1>>40), byte(h1>>48), byte(h1>>56), | |
byte(h2), byte(h2>>8), byte(h2>>16), byte(h2>>24), byte(h2>>32), | |
byte(h2>>40), byte(h2>>48), byte(h2>>56), | |
) | |
} | |
func main() { | |
var byteArray []byte = SumLittleEndian(0x70b1d2a369c2071c, 0x8e7b3be22cce60c2) | |
fmt.Println(base64.RawURLEncoding.EncodeToString(byteArray)) | |
// The above prints out HAfCaaPSsXDCYM4s4jt7jg | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment