forked from brimdata/super
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typevectortable.go
81 lines (70 loc) · 1.38 KB
/
typevectortable.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
package zed
type TypeVectorTable struct {
types []typeVector
}
func NewTypeVectorTable() *TypeVectorTable {
return &TypeVectorTable{}
}
func (t *TypeVectorTable) Lookup(types []Type) int {
for k, typ := range t.types {
if typ.equal(types) {
return k
}
}
k := len(t.types)
t.types = append(t.types, newTypeVector(types))
return k
}
func (t *TypeVectorTable) LookupByValues(vals []Value) int {
for k, typ := range t.types {
if typ.equalToValues(vals) {
return k
}
}
k := len(t.types)
t.types = append(t.types, newTypeVectorFromValues(vals))
return k
}
func (t *TypeVectorTable) Types(id int) []Type {
return t.types[id]
}
func (t *TypeVectorTable) Length() int {
return len(t.types)
}
type typeVector []Type
func newTypeVector(in []Type) typeVector {
out := make(typeVector, 0, len(in))
for _, t := range in {
out = append(out, t)
}
return out
}
func newTypeVectorFromValues(vals []Value) typeVector {
out := make(typeVector, 0, len(vals))
for _, zv := range vals {
out = append(out, zv.Type)
}
return out
}
func (t typeVector) equal(to []Type) bool {
if len(t) != len(to) {
return false
}
for k, typ := range t {
if typ != to[k] {
return false
}
}
return true
}
func (t typeVector) equalToValues(vals []Value) bool {
if len(t) != len(vals) {
return false
}
for k, typ := range t {
if typ != vals[k].Type {
return false
}
}
return true
}