Created
June 5, 2018 17:20
-
-
Save tsuna/56996c34f7a1c57a2e65e2e8194ad4c8 to your computer and use it in GitHub Desktop.
How to hash strings in Go
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
package gist | |
import "unsafe" | |
//go:noescape | |
//go:linkname strhash runtime.strhash | |
func strhash(a unsafe.Pointer, h uintptr) uintptr | |
// StrHash returns the hash of the given string. | |
func StrHash(s string) uintptr { | |
return strhash(unsafe.Pointer(&s), 0) | |
} |
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 file is intentionally empty. It must be kept along side hash.go. | |
// It's a workaround for https://github.com/golang/go/issues/15006 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment