Debian Codegraph @

dstream/filtercol.go

raw symbols SCIP
1 package dstream
2
3 // FilterFunc is a filtering function for use with Filter. The first
4 // argument holds a map from variable names to data slices. The second
5 // argument is a boolean slice that is initialized to all 'true'. The
6 // FilterFunc should set elements of the boolean slice to false wherever
7 // the corresponding dstream record should be excluded.
8 type FilterFunc func(map[string]interface{}, []bool)
9
10 type filterCol struct {
11 xform
12
13 filter FilterFunc
14 keep []bool
15 keeppos []int
16 nobs int
17 nobsKnown bool
18 }
19
20 // Filter selects rows from the dstream. A filtering function determines
21 // which rows are selected.
22 func Filter(data Dstream, f FilterFunc) Dstream {
23
24 fc := &filterCol{
25 xform: xform{
26 source: data,
27 },
28 filter: f,
29 }
30 fc.init()
31
32 return fc
33 }
34
35 func (fc *filterCol) init() {
36 fc.names = fc.source.Names()
37
38 // We need to know this early so call explicitly
39 fc.setNamePos()
40
41 fc.bdata = make([]interface{}, len(fc.names))
42 fc.nobsKnown = false
43 fc.nobs = 0
44 }
45
46 func (fc *filterCol) Reset() {
47 fc.source.Reset()
48 fc.nobs = 0
49 fc.nobsKnown = false
50 fc.init()
51 }
52
53 func (fc *filterCol) NumObs() int {
54 if fc.nobsKnown {
55 return fc.nobs
56 }
57 return -1
58 }