-
Notifications
You must be signed in to change notification settings - Fork 67
/
array.go
63 lines (51 loc) · 1.24 KB
/
array.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
package zbuf
import (
"github.com/brimdata/zed"
"github.com/brimdata/zed/zio"
)
// Array is a slice of of records that implements the Batch and
// the Reader interfaces.
type Array struct {
values []zed.Value
vars []zed.Value
}
var _ Batch = (*Array)(nil)
var _ zio.Reader = (*Array)(nil)
var _ zio.Writer = (*Array)(nil)
// XXX this should take the frame arg too and the procs that create
// new arrays need to propagate their frames downstream.
func NewArray(vals []zed.Value) *Array {
return &Array{values: vals}
}
func (a *Array) Ref() {
// do nothing... let the GC reclaim it
}
func (a *Array) Unref() {
// do nothing... let the GC reclaim it
}
func (a *Array) Values() []zed.Value {
return a.values
}
func (a *Array) Append(r zed.Value) {
a.values = append(a.values, r)
}
func (a *Array) SetVars(vars []zed.Value) {
a.vars = vars
}
func (a *Array) Vars() []zed.Value {
return a.vars
}
func (a *Array) Write(r zed.Value) error {
a.Append(r.Copy())
return nil
}
// Read returns removes the first element of the Array and returns it,
// or it returns nil if the Array is empty.
func (a *Array) Read() (*zed.Value, error) {
var rec *zed.Value
if len(a.values) > 0 {
rec = &a.values[0]
a.values = a.values[1:]
}
return rec, nil
}