github.com/QuangTung97/bigcache@v0.1.0/memhash/memhash.go (about) 1 package memhash 2 3 import "unsafe" 4 5 // NanoTime returns the current time in nanoseconds from a monotonic clock. 6 //go:linkname NanoTime runtime.nanotime 7 func NanoTime() int64 8 9 type stringStruct struct { 10 str unsafe.Pointer 11 len int 12 } 13 14 //go:noescape 15 //go:linkname memhash runtime.memhash 16 func memhash(p unsafe.Pointer, h, s uintptr) uintptr 17 18 // Hash is the hash function used by go map, it utilizes available hardware instructions(behaves 19 // as aeshash if aes instruction is available). 20 // NOTE: The hash seed changes for every process. So, this cannot be used as a persistent hash. 21 func Hash(data []byte) uint64 { 22 ss := (*stringStruct)(unsafe.Pointer(&data)) 23 return uint64(memhash(ss.str, 0, uintptr(ss.len))) 24 }