github.com/grailbio/bigslice@v0.0.0-20230519005545-30c4c12152ad/frame/ops_builtin.go (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 13 RegisterOps(func(slice []string) Ops { 14 return Ops{ 15 Less: func(i, j int) bool { return slice[i] < slice[j] }, 16 HashWithSeed: func(i int, seed uint32) uint32 { 17 return murmur3.Sum32WithSeed([]byte(slice[i]), seed) 18 }, 19 } 20 }) 21 22 RegisterOps(func(slice []uint) Ops { 23 return Ops{ 24 Less: func(i, j int) bool { return slice[i] < slice[j] }, 25 HashWithSeed: func(i int, seed uint32) uint32 { 26 return hash64(uint64(slice[i]), seed) 27 }, 28 } 29 }) 30 31 RegisterOps(func(slice []uint8) Ops { 32 return Ops{ 33 Less: func(i, j int) bool { return slice[i] < slice[j] }, 34 HashWithSeed: func(i int, seed uint32) uint32 { 35 return hash32(uint32(slice[i]), seed) 36 }, 37 } 38 }) 39 40 RegisterOps(func(slice []uint16) Ops { 41 return Ops{ 42 Less: func(i, j int) bool { return slice[i] < slice[j] }, 43 HashWithSeed: func(i int, seed uint32) uint32 { 44 return hash32(uint32(slice[i]), seed) 45 }, 46 } 47 }) 48 49 RegisterOps(func(slice []uint32) Ops { 50 return Ops{ 51 Less: func(i, j int) bool { return slice[i] < slice[j] }, 52 HashWithSeed: func(i int, seed uint32) uint32 { 53 return hash32(uint32(slice[i]), seed) 54 }, 55 } 56 }) 57 58 RegisterOps(func(slice []uint64) Ops { 59 return Ops{ 60 Less: func(i, j int) bool { return slice[i] < slice[j] }, 61 HashWithSeed: func(i int, seed uint32) uint32 { 62 return hash64(uint64(slice[i]), seed) 63 }, 64 } 65 }) 66 67 RegisterOps(func(slice []int) Ops { 68 return Ops{ 69 Less: func(i, j int) bool { return slice[i] < slice[j] }, 70 HashWithSeed: func(i int, seed uint32) uint32 { 71 return hash64(uint64(slice[i]), seed) 72 }, 73 } 74 }) 75 76 RegisterOps(func(slice []int8) Ops { 77 return Ops{ 78 Less: func(i, j int) bool { return slice[i] < slice[j] }, 79 HashWithSeed: func(i int, seed uint32) uint32 { 80 return hash32(uint32(slice[i]), seed) 81 }, 82 } 83 }) 84 85 RegisterOps(func(slice []int16) Ops { 86 return Ops{ 87 Less: func(i, j int) bool { return slice[i] < slice[j] }, 88 HashWithSeed: func(i int, seed uint32) uint32 { 89 return hash32(uint32(slice[i]), seed) 90 }, 91 } 92 }) 93 94 RegisterOps(func(slice []int32) Ops { 95 return Ops{ 96 Less: func(i, j int) bool { return slice[i] < slice[j] }, 97 HashWithSeed: func(i int, seed uint32) uint32 { 98 return hash32(uint32(slice[i]), seed) 99 }, 100 } 101 }) 102 103 RegisterOps(func(slice []int64) Ops { 104 return Ops{ 105 Less: func(i, j int) bool { return slice[i] < slice[j] }, 106 HashWithSeed: func(i int, seed uint32) uint32 { 107 return hash64(uint64(slice[i]), seed) 108 }, 109 } 110 }) 111 112 RegisterOps(func(slice []float32) Ops { 113 return Ops{ 114 Less: func(i, j int) bool { return slice[i] < slice[j] }, 115 HashWithSeed: func(i int, seed uint32) uint32 { 116 return hash32(math.Float32bits(slice[i]), seed) 117 }, 118 } 119 }) 120 121 RegisterOps(func(slice []float64) Ops { 122 return Ops{ 123 Less: func(i, j int) bool { return slice[i] < slice[j] }, 124 HashWithSeed: func(i int, seed uint32) uint32 { 125 return hash64(math.Float64bits(slice[i]), seed) 126 }, 127 } 128 }) 129 130 RegisterOps(func(slice []uintptr) Ops { 131 return Ops{ 132 Less: func(i, j int) bool { return slice[i] < slice[j] }, 133 HashWithSeed: func(i int, seed uint32) uint32 { 134 return hash64(uint64(slice[i]), seed) 135 }, 136 } 137 }) 138 139 } 140 141 // Hash32 is the 32-bit integer hashing function from 142 // http://burtleburtle.net/bob/hash/integer.html. (Public domain.) 143 func hash32(x, seed uint32) uint32 { 144 var b [4]byte 145 b[0] = byte(x) 146 b[1] = byte(x >> 8) 147 b[2] = byte(x >> 16) 148 b[3] = byte(x >> 24) 149 return murmur3.Sum32WithSeed(b[:], seed) 150 } 151 152 // Hash64 uses hash32 to compute a 64-bit integer hash. 153 func hash64(x uint64, seed uint32) uint32 { 154 var b [8]byte 155 b[0] = byte(x) 156 b[1] = byte(x >> 8) 157 b[2] = byte(x >> 16) 158 b[3] = byte(x >> 24) 159 b[4] = byte(x >> 32) 160 b[5] = byte(x >> 40) 161 b[6] = byte(x >> 48) 162 b[7] = byte(x >> 56) 163 return murmur3.Sum32WithSeed(b[:], seed) 164 }