Debian Codegraph @

dstream/utils_gen.go

raw symbols SCIP
1 // GENERATED CODE, DO NOT EDIT
2
3 package dstream
4
5 import (
6 "fmt"
7 "time"
8 )
9
10 // Resize returns a slice of the given type having size n,
11 // re-using the provided slice if it is big enough.
12 func resizeString(x []string, n int) []string {
13 if cap(x) < n {
14 x = make([]string, n)
15 }
16 return x[0:n]
17 }
18
19 // Resize returns a slice of the given type having size n,
20 // re-using the provided slice if it is big enough.
21 func resizeTime(x []time.Time, n int) []time.Time {
22 if cap(x) < n {
23 x = make([]time.Time, n)
24 }
25 return x[0:n]
26 }
27
28 // Resize returns a slice of the given type having size n,
29 // re-using the provided slice if it is big enough.
30 func resizeUint8(x []uint8, n int) []uint8 {
31 if cap(x) < n {
32 x = make([]uint8, n)
33 }
34 return x[0:n]
35 }
36
37 // Resize returns a slice of the given type having size n,
38 // re-using the provided slice if it is big enough.
39 func resizeUint16(x []uint16, n int) []uint16 {
40 if cap(x) < n {
41 x = make([]uint16, n)
42 }
43 return x[0:n]
44 }
45
46 // Resize returns a slice of the given type having size n,
47 // re-using the provided slice if it is big enough.
48 func resizeUint32(x []uint32, n int) []uint32 {
49 if cap(x) < n {
50 x = make([]uint32, n)
51 }
52 return x[0:n]
53 }
54
55 // Resize returns a slice of the given type having size n,
56 // re-using the provided slice if it is big enough.
57 func resizeUint64(x []uint64, n int) []uint64 {
58 if cap(x) < n {
59 x = make([]uint64, n)
60 }
61 return x[0:n]
62 }
63
64 // Resize returns a slice of the given type having size n,
65 // re-using the provided slice if it is big enough.
66 func resizeInt8(x []int8, n int) []int8 {
67 if cap(x) < n {
68 x = make([]int8, n)
69 }
70 return x[0:n]
71 }
72
73 // Resize returns a slice of the given type having size n,
74 // re-using the provided slice if it is big enough.
75 func resizeInt16(x []int16, n int) []int16 {
76 if cap(x) < n {
77 x = make([]int16, n)
78 }
79 return x[0:n]
80 }
81
82 // Resize returns a slice of the given type having size n,
83 // re-using the provided slice if it is big enough.
84 func resizeInt32(x []int32, n int) []int32 {
85 if cap(x) < n {
86 x = make([]int32, n)
87 }
88 return x[0:n]
89 }
90
91 // Resize returns a slice of the given type having size n,
92 // re-using the provided slice if it is big enough.
93 func resizeInt64(x []int64, n int) []int64 {
94 if cap(x) < n {
95 x = make([]int64, n)
96 }
97 return x[0:n]
98 }
99
100 // Resize returns a slice of the given type having size n,
101 // re-using the provided slice if it is big enough.
102 func resizeFloat32(x []float32, n int) []float32 {
103 if cap(x) < n {
104 x = make([]float32, n)
105 }
106 return x[0:n]
107 }
108
109 // Resize returns a slice of the given type having size n,
110 // re-using the provided slice if it is big enough.
111 func resizeFloat64(x []float64, n int) []float64 {
112 if cap(x) < n {
113 x = make([]float64, n)
114 }
115 return x[0:n]
116 }
117
118 // VarTypes returns a map relating each variable by name to its corresponding
119 // data type. The dstream should be readable before calling (Reset and call
120 // Next if needed).
121 func VarTypes(d Dstream) map[string]string {
122 types := make(map[string]string)
123 for k, na := range d.Names() {
124 v := d.GetPos(k)
125 switch v.(type) {
126 case []string:
127 types[na] = "string"
128 case []time.Time:
129 types[na] = "time.Time"
130 case []uint8:
131 types[na] = "uint8"
132 case []uint16:
133 types[na] = "uint16"
134 case []uint32:
135 types[na] = "uint32"
136 case []uint64:
137 types[na] = "uint64"
138 case []int8:
139 types[na] = "int8"
140 case []int16:
141 types[na] = "int16"
142 case []int32:
143 types[na] = "int32"
144 case []int64:
145 types[na] = "int64"
146 case []float32:
147 types[na] = "float32"
148 case []float64:
149 types[na] = "float64"
150 default:
151 types[na] = "unknown type"
152 }
153 }
154 return types
155 }
156
157 func ilen(x interface{}) int {
158 switch x := x.(type) {
159 case []string:
160 return len(x)
161 case []time.Time:
162 return len(x)
163 case []uint8:
164 return len(x)
165 case []uint16:
166 return len(x)
167 case []uint32:
168 return len(x)
169 case []uint64:
170 return len(x)
171 case []int8:
172 return len(x)
173 case []int16:
174 return len(x)
175 case []int32:
176 return len(x)
177 case []int64:
178 return len(x)
179 case []float32:
180 return len(x)
181 case []float64:
182 return len(x)
183 case nil:
184 return 0
185 default:
186 msg := fmt.Sprintf("unknown type: %T", x)
187 panic(msg)
188 }
189 }
190
191 func truncate(z []interface{}) {
192 for j, x := range z {
193 if x != nil {
194 switch x := x.(type) {
195 case []string:
196 z[j] = x[0:0]
197 case []time.Time:
198 z[j] = x[0:0]
199 case []uint8:
200 z[j] = x[0:0]
201 case []uint16:
202 z[j] = x[0:0]
203 case []uint32:
204 z[j] = x[0:0]
205 case []uint64:
206 z[j] = x[0:0]
207 case []int8:
208 z[j] = x[0:0]
209 case []int16:
210 z[j] = x[0:0]
211 case []int32:
212 z[j] = x[0:0]
213 case []int64:
214 z[j] = x[0:0]
215 case []float32:
216 z[j] = x[0:0]
217 case []float64:
218 z[j] = x[0:0]
219 default:
220 msg := fmt.Sprintf("unknown type %T", x)
221 panic(msg)
222 }
223 }
224 }
225 }
226
227 // GetCol returns a copy of the data for one variable. The data
228 // are returned as a slice. The column is returned starting with the
229 // current chunk, call Reset to ensure that the column is extracted
230 // from the first chunk.
231 func GetCol(da Dstream, na string) interface{} {
232
233 vn := da.Names()
234 for j, x := range vn {
235 if na == x {
236 return GetColPos(da, j)
237 }
238 }
239 panic(fmt.Sprintf("GetCol: variable '%s' not found", na))
240 return nil
241 }
242
243 // GetColPos returns a copy of the data for one variable.
244 // The data are returned as a slice, which is a coy of the
245 // underlying data.
246 func GetColPos(da Dstream, j int) interface{} {
247
248 da.Reset()
249
250 if !da.Next() {
251 return nil
252 }
253
254 // Get the first chunk so that we have the data type.
255 v := da.GetPos(j)
256
257 switch v := v.(type) {
258 case []string:
259 var x []string
260 x = append(x, v...)
261 for da.Next() {
262 y := da.GetPos(j).([]string)
263 x = append(x, y...)
264 }
265 return x
266 case []time.Time:
267 var x []time.Time
268 x = append(x, v...)
269 for da.Next() {
270 y := da.GetPos(j).([]time.Time)
271 x = append(x, y...)
272 }
273 return x
274 case []uint8:
275 var x []uint8
276 x = append(x, v...)
277 for da.Next() {
278 y := da.GetPos(j).([]uint8)
279 x = append(x, y...)
280 }
281 return x
282 case []uint16:
283 var x []uint16
284 x = append(x, v...)
285 for da.Next() {
286 y := da.GetPos(j).([]uint16)
287 x = append(x, y...)
288 }
289 return x
290 case []uint32:
291 var x []uint32
292 x = append(x, v...)
293 for da.Next() {
294 y := da.GetPos(j).([]uint32)
295 x = append(x, y...)
296 }
297 return x
298 case []uint64:
299 var x []uint64
300 x = append(x, v...)
301 for da.Next() {
302 y := da.GetPos(j).([]uint64)
303 x = append(x, y...)
304 }
305 return x
306 case []int8:
307 var x []int8
308 x = append(x, v...)
309 for da.Next() {
310 y := da.GetPos(j).([]int8)
311 x = append(x, y...)
312 }
313 return x
314 case []int16:
315 var x []int16
316 x = append(x, v...)
317 for da.Next() {
318 y := da.GetPos(j).([]int16)
319 x = append(x, y...)
320 }
321 return x
322 case []int32:
323 var x []int32
324 x = append(x, v...)
325 for da.Next() {
326 y := da.GetPos(j).([]int32)
327 x = append(x, y...)
328 }
329 return x
330 case []int64:
331 var x []int64
332 x = append(x, v...)
333 for da.Next() {
334 y := da.GetPos(j).([]int64)
335 x = append(x, y...)
336 }
337 return x
338 case []float32:
339 var x []float32
340 x = append(x, v...)
341 for da.Next() {
342 y := da.GetPos(j).([]float32)
343 x = append(x, y...)
344 }
345 return x
346 case []float64:
347 var x []float64
348 x = append(x, v...)
349 for da.Next() {
350 y := da.GetPos(j).([]float64)
351 x = append(x, y...)
352 }
353 return x
354 case nil:
355 return nil
356 default:
357 msg := fmt.Sprintf("GetCol: unknown data type %T.\n", v)
358 panic(msg)
359 }
360 }
361
362 // equalSlice returns true if x and y are slices of the same type and
363 // hold equal values.
364 func equalSlice(x, y interface{}) bool {
365
366 switch u := x.(type) {
367 case []string:
368 v, ok := y.([]string)
369 if !ok {
370 return false
371 }
372 if len(u) != len(v) {
373 return false
374 }
375 for i := range u {
376 if u[i] != v[i] {
377 return false
378 }
379 }
380 case []time.Time:
381 v, ok := y.([]time.Time)
382 if !ok {
383 return false
384 }
385 if len(u) != len(v) {
386 return false
387 }
388 for i := range u {
389 if u[i] != v[i] {
390 return false
391 }
392 }
393 case []uint8:
394 v, ok := y.([]uint8)
395 if !ok {
396 return false
397 }
398 if len(u) != len(v) {
399 return false
400 }
401 for i := range u {
402 if u[i] != v[i] {
403 return false
404 }
405 }
406 case []uint16:
407 v, ok := y.([]uint16)
408 if !ok {
409 return false
410 }
411 if len(u) != len(v) {
412 return false
413 }
414 for i := range u {
415 if u[i] != v[i] {
416 return false
417 }
418 }
419 case []uint32:
420 v, ok := y.([]uint32)
421 if !ok {
422 return false
423 }
424 if len(u) != len(v) {
425 return false
426 }
427 for i := range u {
428 if u[i] != v[i] {
429 return false
430 }
431 }
432 case []uint64:
433 v, ok := y.([]uint64)
434 if !ok {
435 return false
436 }
437 if len(u) != len(v) {
438 return false
439 }
440 for i := range u {
441 if u[i] != v[i] {
442 return false
443 }
444 }
445 case []int8:
446 v, ok := y.([]int8)
447 if !ok {
448 return false
449 }
450 if len(u) != len(v) {
451 return false
452 }
453 for i := range u {
454 if u[i] != v[i] {
455 return false
456 }
457 }
458 case []int16:
459 v, ok := y.([]int16)
460 if !ok {
461 return false
462 }
463 if len(u) != len(v) {
464 return false
465 }
466 for i := range u {
467 if u[i] != v[i] {
468 return false
469 }
470 }
471 case []int32:
472 v, ok := y.([]int32)
473 if !ok {
474 return false
475 }
476 if len(u) != len(v) {
477 return false
478 }
479 for i := range u {
480 if u[i] != v[i] {
481 return false
482 }
483 }
484 case []int64:
485 v, ok := y.([]int64)
486 if !ok {
487 return false
488 }
489 if len(u) != len(v) {
490 return false
491 }
492 for i := range u {
493 if u[i] != v[i] {
494 return false
495 }
496 }
497 case []float32:
498 v, ok := y.([]float32)
499 if !ok {
500 return false
501 }
502 if len(u) != len(v) {
503 return false
504 }
505 for i := range u {
506 if u[i] != v[i] {
507 return false
508 }
509 }
510 case []float64:
511 v, ok := y.([]float64)
512 if !ok {
513 return false
514 }
515 if len(u) != len(v) {
516 return false
517 }
518 for i := range u {
519 if u[i] != v[i] {
520 return false
521 }
522 }
523 default:
524 panic("unkown type")
525 }
526
527 return true
528 }