github.com/gitbookio/syncgroup@v0.0.0-20181003125046-3e73b2e6a972/quickhash/strhash.go (about) 1 package quickhash 2 3 import ( 4 _ "runtime" 5 "unsafe" // required to use //go:linkname 6 ) 7 8 //go:noescape 9 //go:linkname useAeshash runtime.useAeshash 10 var useAeshash bool 11 12 //go:noescape 13 //go:linkname strhash runtime.strhash 14 func strhash(a unsafe.Pointer, h uintptr) uintptr 15 16 //go:noescape 17 //go:linkname aeshashstr runtime.aeshashstr 18 func aeshashstr(p unsafe.Pointer, h uintptr) uintptr 19 20 func StrHash(str string) uint64 { 21 if useAeshash { 22 return uint64(aeshashstr(unsafe.Pointer(&str), 0)) 23 } 24 return uint64(strhash(unsafe.Pointer(&str), 0)) 25 } 26 27 func AesHash(str string) uint64 { 28 return uint64(aeshashstr(unsafe.Pointer(&str), 0)) 29 } 30 31 func ByteHash(data []byte) uint64 { 32 if useAeshash { 33 return uint64(aeshashstr(unsafe.Pointer(&data), 0)) 34 } 35 return uint64(strhash(unsafe.Pointer(&data), 0)) 36 } 37 38 func AesByteHash(data []byte) uint64 { 39 return uint64(aeshashstr(unsafe.Pointer(&data), 0)) 40 }