-
Notifications
You must be signed in to change notification settings - Fork 4
/
row_based_typed.go
64 lines (56 loc) · 1.21 KB
/
row_based_typed.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
package main
type T int
const (
// Int64Type is a value of type int64
Int64Type T = iota
// Float64Type is a value of type float64
Float64Type
)
type TypedDatum struct {
t T
int64 int64
float64 float64
}
type TypedOperator interface {
next() []TypedDatum
}
type typedTableReader struct {
curIdx int
rows [][]TypedDatum
}
func (t *typedTableReader) next() []TypedDatum {
if t.curIdx >= len(t.rows) {
return nil
}
row := t.rows[t.curIdx]
t.curIdx++
return row
}
func (t *typedTableReader) reset() {
t.curIdx = 0
}
// makeTypedInput creates numRows rows of numCols each of the given type. For
// each row, all of its columns will be its index (zero-indexed).
func makeTypedInput(numRows int, numCols int, t T) [][]TypedDatum {
result := make([][]TypedDatum, numRows)
for i := range result {
result[i] = make([]TypedDatum, numCols)
}
switch t {
case Int64Type:
for i := 0; i < numRows; i++ {
for j := 0; j < numCols; j++ {
result[i][j] = TypedDatum{t: t, int64: int64(i)}
}
}
case Float64Type:
for i := 0; i < numRows; i++ {
for j := 0; j < numCols; j++ {
result[i][j] = TypedDatum{t: t, float64: float64(i)}
}
}
default:
panic("unhandled type")
}
return result
}