-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy patharray.go
More file actions
68 lines (58 loc) · 1.24 KB
/
array.go
File metadata and controls
68 lines (58 loc) · 1.24 KB
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
package vector
import (
"github.com/brimdata/super"
"github.com/brimdata/super/scode"
)
type Array struct {
Typ *super.TypeArray
Offsets []uint32
Values Any
}
var _ Any = (*Array)(nil)
func NewArray(typ *super.TypeArray, offsets []uint32, values Any) *Array {
return &Array{typ, offsets, values}
}
func (*Array) Kind() Kind {
return KindArray
}
func (a *Array) Type() super.Type {
return a.Typ
}
func (a *Array) Len() uint32 {
return uint32(len(a.Offsets) - 1)
}
func (a *Array) Serialize(b *scode.Builder, slot uint32) {
off := a.Offsets[slot]
b.BeginContainer()
for end := a.Offsets[slot+1]; off < end; off++ {
a.Values.Serialize(b, off)
}
b.EndContainer()
}
func ContainerOffset(val Any, slot uint32) (uint32, uint32) {
switch val := val.(type) {
case *Array:
return val.Offsets[slot], val.Offsets[slot+1]
case *Set:
return val.Offsets[slot], val.Offsets[slot+1]
case *Map:
return val.Offsets[slot], val.Offsets[slot+1]
case *View:
slot = val.Index[slot]
return ContainerOffset(val.Any, slot)
}
panic(val)
}
func Inner(val Any) Any {
switch val := val.(type) {
case *Array:
return val.Values
case *Set:
return val.Values
case *Dict:
return Inner(val.Any)
case *View:
return Inner(val.Any)
}
panic(val)
}