Skip to content

Instantly share code, notes, and snippets.

@tsuna
Created June 5, 2018 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsuna/56996c34f7a1c57a2e65e2e8194ad4c8 to your computer and use it in GitHub Desktop.
Save tsuna/56996c34f7a1c57a2e65e2e8194ad4c8 to your computer and use it in GitHub Desktop.
How to hash strings in Go
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 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