package maphash
import (
"internal/abi"
"internal/goarch"
"internal/goexperiment"
"unsafe"
)
const purego = false
func runtime_rand() uint64
func runtime_memhash(p unsafe .Pointer , seed , s uintptr ) uintptr
func rthash(buf []byte , seed uint64 ) uint64 {
if len (buf ) == 0 {
return seed
}
len := len (buf )
if goarch .PtrSize == 8 {
return uint64 (runtime_memhash (unsafe .Pointer (&buf [0 ]), uintptr (seed ), uintptr (len )))
}
lo := runtime_memhash (unsafe .Pointer (&buf [0 ]), uintptr (seed ), uintptr (len ))
hi := runtime_memhash (unsafe .Pointer (&buf [0 ]), uintptr (seed >>32 ), uintptr (len ))
return uint64 (hi )<<32 | uint64 (lo )
}
func rthashString(s string , state uint64 ) uint64 {
buf := unsafe .Slice (unsafe .StringData (s ), len (s ))
return rthash (buf , state )
}
func randUint64() uint64 {
return runtime_rand ()
}
func comparableHash[T comparable ](v T , seed Seed ) uint64 {
s := seed .s
var m map [T ]struct {}
mTyp := abi .TypeOf (m )
var hasher func (unsafe .Pointer , uintptr ) uintptr
if goexperiment .SwissMap {
hasher = (*abi .SwissMapType )(unsafe .Pointer (mTyp )).Hasher
} else {
hasher = (*abi .OldMapType )(unsafe .Pointer (mTyp )).Hasher
}
if goarch .PtrSize == 8 {
return uint64 (hasher (abi .NoEscape (unsafe .Pointer (&v )), uintptr (s )))
}
lo := hasher (abi .NoEscape (unsafe .Pointer (&v )), uintptr (s ))
hi := hasher (abi .NoEscape (unsafe .Pointer (&v )), uintptr (s >>32 ))
return uint64 (hi )<<32 | uint64 (lo )
}
func writeComparable[T comparable ](h *Hash , v T ) {
h .state .s = comparableHash (v , h .state )
}
The pages are generated with Golds v0.7.3 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .