github.com/fufuok/utils@v1.0.10/xhash/hash_seed.go (about)

     1  //go:build !go1.19
     2  // +build !go1.19
     3  
     4  package xhash
     5  
     6  import (
     7  	"hash/maphash"
     8  	"reflect"
     9  	"unsafe"
    10  )
    11  
    12  // hashString calculates a hash of s with the given seed.
    13  func hashString(seed maphash.Seed, s string) uint64 {
    14  	seed64 := *(*uint64)(unsafe.Pointer(&seed))
    15  	if s == "" {
    16  		return seed64
    17  	}
    18  	strh := (*reflect.StringHeader)(unsafe.Pointer(&s))
    19  	return uint64(memhash(unsafe.Pointer(strh.Data), uintptr(seed64), uintptr(strh.Len)))
    20  }