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