-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsink.go
More file actions
72 lines (68 loc) · 1.54 KB
/
sink.go
File metadata and controls
72 lines (68 loc) · 1.54 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
69
70
71
72
package data
import (
"go4ml.xyz/fu"
"go4ml.xyz/lazy"
)
func sink1(t *Table, res int) []lazy.Worker {
var fr *varframe
return []lazy.Worker{func(_ int, v interface{}, err error) (_ error) {
if v != nil {
switch r := v.(type) {
case *Row:
if fr == nil {
fr = &varframe{
maxVarpartLength: fu.Maxi(defaultMaxVarpartLength, res),
reserveOnStart: res,
}
fr.factory.InitFrom(r.Factory)
}
fr.append(r.Data)
r.Recycle()
}
} else if err == nil {
*t = Table{fr}
}
return nil
}}
}
func sink2(t *Table, res int, concurrency int) []lazy.Worker {
wf := make([]lazy.Worker, concurrency)
vf := make([]*varframe, concurrency)
ndx := make([][]int, concurrency)
res = res/concurrency + res/10
for k := range wf {
wf[k] = func(w int, fr *varframe) lazy.Worker {
return func(i int, v interface{}, e error) error {
if v != nil {
switch r := v.(type) {
case *Row:
if fr == nil {
fr = &varframe{
maxVarpartLength: fu.Maxi(defaultMaxVarpartLength, res),
reserveOnStart: res,
}
fr.factory.InitFrom(r.Factory)
vf[w] = fr
}
fr.append(r.Data)
ndx[w] = append(ndx[w], i)
r.Recycle()
}
} else if e == nil {
*t = Table{ccrComplete(vf, ndx)}
}
return nil
}
}(k, nil)
}
return wf
}
func (t *Table) Sink(reserve ...int) lazy.WorkerFactory {
res := fu.Fnzi(reserve...)
return func(concurrency int) []lazy.Worker {
if concurrency < 2 {
return sink1(t, res)
}
return sink2(t, res, concurrency)
}
}