Source file
src/hash/maphash/maphash_runtime.go
1
2
3
4
5
6
7 package maphash
8
9 import (
10 "unsafe"
11 )
12
13
14 func runtime_rand() uint64
15
16
17
18 func runtime_memhash(p unsafe.Pointer, seed, s uintptr) uintptr
19
20 func rthash(buf []byte, seed uint64) uint64 {
21 if len(buf) == 0 {
22 return seed
23 }
24 len := len(buf)
25
26
27
28 if unsafe.Sizeof(uintptr(0)) == 8 {
29 return uint64(runtime_memhash(unsafe.Pointer(&buf[0]), uintptr(seed), uintptr(len)))
30 }
31 lo := runtime_memhash(unsafe.Pointer(&buf[0]), uintptr(seed), uintptr(len))
32 hi := runtime_memhash(unsafe.Pointer(&buf[0]), uintptr(seed>>32), uintptr(len))
33 return uint64(hi)<<32 | uint64(lo)
34 }
35
36 func rthashString(s string, state uint64) uint64 {
37 buf := unsafe.Slice(unsafe.StringData(s), len(s))
38 return rthash(buf, state)
39 }
40
41 func randUint64() uint64 {
42 return runtime_rand()
43 }
44
View as plain text