-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconcat.go
64 lines (58 loc) · 1.31 KB
/
concat.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
package datatable
// Concat datatables
func (left *DataTable) Concat(table ...*DataTable) (*DataTable, error) {
out := left.EmptyCopy()
out.dirty = true
tables := make([]*DataTable, 0, 1+len(table))
tables = append(tables, left)
tables = append(tables, table...)
for _, t := range tables {
if t == nil {
continue
}
for _, tc := range t.cols {
pos := out.ColumnIndex(tc.name)
if pos >= 0 {
oc := out.cols[pos]
if oc.IsComputed() {
oc.serie.Grow(out.nrows - oc.serie.Len() + tc.serie.Len())
continue
}
if err := oc.serie.Concat(tc.serie); err != nil {
return nil, err
}
} else {
out.cols = append(out.cols, tc.emptyCopy())
oc := out.cols[len(out.cols)-1]
oc.serie.Grow(out.nrows - oc.serie.Len())
if oc.IsComputed() {
oc.serie.Grow(tc.serie.Len())
continue
}
if err := oc.serie.Concat(tc.serie); err != nil {
return nil, err
}
}
}
out.nrows += t.nrows
}
// check
for _, oc := range out.cols {
size := out.nrows - oc.serie.Len()
if size > 0 {
oc.serie.Grow(size)
}
}
return out, nil
}
// Concat datatables
func Concat(tables []*DataTable) (*DataTable, error) {
switch len(tables) {
case 0:
return nil, ErrNoTables
case 1:
return tables[0].Concat()
default:
return tables[0].Concat(tables[1:]...)
}
}