github.com/parquet-go/parquet-go@v0.21.1-0.20240501160520-b3c3a0c3ed6f/dictionary_purego.go (about) 1 //go:build purego || !amd64 2 3 package parquet 4 5 import ( 6 "unsafe" 7 8 "github.com/parquet-go/parquet-go/sparse" 9 ) 10 11 func (d *int32Dictionary) lookup(indexes []int32, rows sparse.Array) { 12 checkLookupIndexBounds(indexes, rows) 13 for i, j := range indexes { 14 *(*int32)(rows.Index(i)) = d.index(j) 15 } 16 } 17 18 func (d *int64Dictionary) lookup(indexes []int32, rows sparse.Array) { 19 checkLookupIndexBounds(indexes, rows) 20 for i, j := range indexes { 21 *(*int64)(rows.Index(i)) = d.index(j) 22 } 23 } 24 25 func (d *floatDictionary) lookup(indexes []int32, rows sparse.Array) { 26 checkLookupIndexBounds(indexes, rows) 27 for i, j := range indexes { 28 *(*float32)(rows.Index(i)) = d.index(j) 29 } 30 } 31 32 func (d *doubleDictionary) lookup(indexes []int32, rows sparse.Array) { 33 checkLookupIndexBounds(indexes, rows) 34 for i, j := range indexes { 35 *(*float64)(rows.Index(i)) = d.index(j) 36 } 37 } 38 39 func (d *byteArrayDictionary) lookupString(indexes []int32, rows sparse.Array) { 40 checkLookupIndexBounds(indexes, rows) 41 for i, j := range indexes { 42 v := d.index(int(j)) 43 *(*string)(rows.Index(i)) = *(*string)(unsafe.Pointer(&v)) 44 } 45 } 46 47 func (d *fixedLenByteArrayDictionary) lookupString(indexes []int32, rows sparse.Array) { 48 checkLookupIndexBounds(indexes, rows) 49 for i, j := range indexes { 50 v := d.index(j) 51 *(*string)(rows.Index(i)) = *(*string)(unsafe.Pointer(&v)) 52 } 53 } 54 55 func (d *uint32Dictionary) lookup(indexes []int32, rows sparse.Array) { 56 checkLookupIndexBounds(indexes, rows) 57 for i, j := range indexes { 58 *(*uint32)(rows.Index(i)) = d.index(j) 59 } 60 } 61 62 func (d *uint64Dictionary) lookup(indexes []int32, rows sparse.Array) { 63 checkLookupIndexBounds(indexes, rows) 64 for i, j := range indexes { 65 *(*uint64)(rows.Index(i)) = d.index(j) 66 } 67 } 68 69 func (d *be128Dictionary) lookupString(indexes []int32, rows sparse.Array) { 70 checkLookupIndexBounds(indexes, rows) 71 s := "0123456789ABCDEF" 72 for i, j := range indexes { 73 *(**[16]byte)(unsafe.Pointer(&s)) = d.index(j) 74 *(*string)(rows.Index(i)) = s 75 } 76 } 77 78 func (d *be128Dictionary) lookupPointer(indexes []int32, rows sparse.Array) { 79 checkLookupIndexBounds(indexes, rows) 80 for i, j := range indexes { 81 *(**[16]byte)(rows.Index(i)) = d.index(j) 82 } 83 } 84 85 func (d *int32Dictionary) bounds(indexes []int32) (min, max int32) { 86 min = d.index(indexes[0]) 87 max = min 88 89 for _, i := range indexes[1:] { 90 value := d.index(i) 91 if value < min { 92 min = value 93 } 94 if value > max { 95 max = value 96 } 97 } 98 99 return min, max 100 } 101 102 func (d *int64Dictionary) bounds(indexes []int32) (min, max int64) { 103 min = d.index(indexes[0]) 104 max = min 105 106 for _, i := range indexes[1:] { 107 value := d.index(i) 108 if value < min { 109 min = value 110 } 111 if value > max { 112 max = value 113 } 114 } 115 116 return min, max 117 } 118 119 func (d *floatDictionary) bounds(indexes []int32) (min, max float32) { 120 min = d.index(indexes[0]) 121 max = min 122 123 for _, i := range indexes[1:] { 124 value := d.index(i) 125 if value < min { 126 min = value 127 } 128 if value > max { 129 max = value 130 } 131 } 132 133 return min, max 134 } 135 136 func (d *doubleDictionary) bounds(indexes []int32) (min, max float64) { 137 min = d.index(indexes[0]) 138 max = min 139 140 for _, i := range indexes[1:] { 141 value := d.index(i) 142 if value < min { 143 min = value 144 } 145 if value > max { 146 max = value 147 } 148 } 149 150 return min, max 151 } 152 153 func (d *uint32Dictionary) bounds(indexes []int32) (min, max uint32) { 154 min = d.index(indexes[0]) 155 max = min 156 157 for _, i := range indexes[1:] { 158 value := d.index(i) 159 if value < min { 160 min = value 161 } 162 if value > max { 163 max = value 164 } 165 } 166 167 return min, max 168 } 169 170 func (d *uint64Dictionary) bounds(indexes []int32) (min, max uint64) { 171 min = d.index(indexes[0]) 172 max = min 173 174 for _, i := range indexes[1:] { 175 value := d.index(i) 176 if value < min { 177 min = value 178 } 179 if value > max { 180 max = value 181 } 182 } 183 184 return min, max 185 } 186 187 func (d *be128Dictionary) bounds(indexes []int32) (min, max *[16]byte) { 188 values := [64]*[16]byte{} 189 min = d.index(indexes[0]) 190 max = min 191 192 for i := 1; i < len(indexes); i += len(values) { 193 n := len(indexes) - i 194 if n > len(values) { 195 n = len(values) 196 } 197 j := i + n 198 d.lookupPointer(indexes[i:j:j], makeArrayBE128(values[:n:n])) 199 200 for _, value := range values[:n:n] { 201 switch { 202 case lessBE128(value, min): 203 min = value 204 case lessBE128(max, value): 205 max = value 206 } 207 } 208 } 209 210 return min, max 211 }