github.com/grailbio/bigslice@v0.0.0-20230519005545-30c4c12152ad/frame/ops_builtin.gotemplate (about) 1 // THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT. 2 3 package frame 4 5 import ( 6 "math" 7 8 "github.com/spaolacci/murmur3" 9 ) 10 11 func init() { 12 {{range .}} 13 14 RegisterOps(func(slice []{{.Type}}) Ops { 15 return Ops{ 16 Less: func(i, j int) bool { return slice[i] < slice[j] }, 17 HashWithSeed: func(i int, seed uint32) uint32 { {{if eq .Type "string" }} 18 return murmur3.Sum32WithSeed([]byte(slice[i]), seed) 19 {{ else if eq .Type "float32" }}return hash32(math.Float32bits(slice[i]), seed) 20 {{ else if eq .Type "uint8" "uint16" "uint32" "int8" "int16" "int32"}}return hash32(uint32(slice[i]), seed) 21 {{ else if eq .Type "float64" }}return hash64(math.Float64bits(slice[i]), seed) 22 {{ else if eq .Type "uint" "int" "uint64" "int64" "uintptr" }}return hash64(uint64(slice[i]), seed) 23 {{end}}}, 24 } 25 }) 26 {{end}} 27 } 28 29 // Hash32 is the 32-bit integer hashing function from 30 // http://burtleburtle.net/bob/hash/integer.html. (Public domain.) 31 func hash32(x, seed uint32) uint32 { 32 var b [4]byte 33 b[0] = byte(x) 34 b[1] = byte(x>>8) 35 b[2] = byte(x>>16) 36 b[3] = byte(x>>24) 37 return murmur3.Sum32WithSeed(b[:], seed) 38 } 39 40 // Hash64 uses hash32 to compute a 64-bit integer hash. 41 func hash64(x uint64, seed uint32) uint32 { 42 var b [8]byte 43 b[0] = byte(x) 44 b[1] = byte(x>>8) 45 b[2] = byte(x>>16) 46 b[3] = byte(x>>24) 47 b[4] = byte(x>>32) 48 b[5] = byte(x>>40) 49 b[6] = byte(x>>48) 50 b[7] = byte(x>>56) 51 return murmur3.Sum32WithSeed(b[:], seed) 52 }