github.com/puzpuzpuz/xsync/v2@v2.5.2-0.20231021165734-92b8269e19a9/util_mapof.go (about)

     1  //go:build go1.18
     2  // +build go1.18
     3  
     4  package xsync
     5  
     6  import (
     7  	"hash/maphash"
     8  	"unsafe"
     9  )
    10  
    11  // hashUint64 calculates a hash of v with the given seed.
    12  //
    13  //lint:ignore U1000 used in MapOf
    14  func hashUint64[K IntegerConstraint](seed maphash.Seed, k K) uint64 {
    15  	n := uint64(k)
    16  	// Java's Long standard hash function.
    17  	n = n ^ (n >> 32)
    18  	nseed := *(*uint64)(unsafe.Pointer(&seed))
    19  	// 64-bit variation of boost's hash_combine.
    20  	nseed ^= n + 0x9e3779b97f4a7c15 + (nseed << 12) + (nseed >> 4)
    21  	return nseed
    22  }