aboutsummaryrefslogtreecommitdiff
path: root/lib/tabula
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-04-05 03:50:32 +0700
committerShulhan <ms@kilabit.info>2026-04-05 03:52:47 +0700
commit778fd16011ec1d39c41b62372dc65f045183266e (patch)
treea6f6f26930c00d8ac3dd7bfa1fb476bd65454833 /lib/tabula
parent6fba7b9ce3bcaf4225e5ab774a15ef7364ed1420 (diff)
downloadpakakeh.go-778fd16011ec1d39c41b62372dc65f045183266e.tar.xz
all: apply go fix
Diffstat (limited to 'lib/tabula')
-rw-r--r--lib/tabula/column.go5
-rw-r--r--lib/tabula/columns.go16
-rw-r--r--lib/tabula/columns_test.go2
-rw-r--r--lib/tabula/dataset.go26
-rw-r--r--lib/tabula/datasetinterface.go10
-rw-r--r--lib/tabula/rows.go17
-rw-r--r--lib/tabula/rows_test.go4
-rw-r--r--lib/tabula/tabula_test.go2
8 files changed, 24 insertions, 58 deletions
diff --git a/lib/tabula/column.go b/lib/tabula/column.go
index b89acffc..1e84e150 100644
--- a/lib/tabula/column.go
+++ b/lib/tabula/column.go
@@ -235,10 +235,7 @@ func (col *Column) SetValues(values []string) {
}
// pick the least length
- minlen := reclen
- if vallen < reclen {
- minlen = vallen
- }
+ minlen := min(vallen, reclen)
for x := range minlen {
_ = col.Records[x].SetValue(values[x], col.Type)
diff --git a/lib/tabula/columns.go b/lib/tabula/columns.go
index 6a79e341..16c3ac32 100644
--- a/lib/tabula/columns.go
+++ b/lib/tabula/columns.go
@@ -5,6 +5,8 @@
package tabula
import (
+ "slices"
+
libbytes "git.sr.ht/~shulhan/pakakeh.go/lib/bytes"
libnumbers "git.sr.ht/~shulhan/pakakeh.go/lib/numbers"
)
@@ -29,11 +31,7 @@ func (cols *Columns) Reset() {
func (cols *Columns) SetTypes(types []int) {
typeslen := len(types)
colslen := len(*cols)
- minlen := typeslen
-
- if colslen < minlen {
- minlen = colslen
- }
+ minlen := min(colslen, typeslen)
for x := range minlen {
(*cols)[x].Type = types[x]
@@ -72,13 +70,7 @@ func (cols *Columns) RandomPick(n int, dup bool, excludeIdx []int) (
// select unpicked columns using picked index.
for cid := range *cols {
// check if column index has been picked up
- isPicked := false
- for _, idx := range pickedIdx {
- if cid == idx {
- isPicked = true
- break
- }
- }
+ isPicked := slices.Contains(pickedIdx, cid)
if !isPicked {
unpicked = append(unpicked, (*cols)[cid])
unpickedIdx = append(unpickedIdx, cid)
diff --git a/lib/tabula/columns_test.go b/lib/tabula/columns_test.go
index f70a6aca..a1dfb0d5 100644
--- a/lib/tabula/columns_test.go
+++ b/lib/tabula/columns_test.go
@@ -27,7 +27,7 @@ func TestRandomPickColumns(t *testing.T) {
dup := false
ncols := 6
excludeIdx := []int{3}
- for i := 0; i < 5; i++ {
+ for range 5 {
picked, unpicked, _, _ :=
dataset.Columns.RandomPick(ncols, dup, excludeIdx)
diff --git a/lib/tabula/dataset.go b/lib/tabula/dataset.go
index 3fee622b..c54e2236 100644
--- a/lib/tabula/dataset.go
+++ b/lib/tabula/dataset.go
@@ -213,10 +213,7 @@ func (dataset *Dataset) SetColumnsName(names []string) {
}
// find minimum length
- minlen := collen
- if nameslen < collen {
- minlen = nameslen
- }
+ minlen := min(nameslen, collen)
for x := range minlen {
dataset.Columns[x].Name = names[x]
@@ -364,11 +361,7 @@ func (dataset *Dataset) TransposeToColumns() {
}
// use the least length
- minlen := len(*dataset.GetRow(0))
-
- if minlen > ncol {
- minlen = ncol
- }
+ minlen := min(len(*dataset.GetRow(0)), ncol)
switch orgmode {
case DatasetModeRows, DatasetNoMode:
@@ -407,7 +400,7 @@ func (dataset *Dataset) TransposeToRows() {
rowlen := math.MinInt32
flen := len(dataset.Columns)
- for f := 0; f < flen; f++ {
+ for f := range flen {
l := dataset.Columns[f].Len()
if l > rowlen {
@@ -421,7 +414,7 @@ func (dataset *Dataset) TransposeToRows() {
for r := 0; r < rowlen; r++ {
row := make(Row, flen)
- for f := 0; f < flen; f++ {
+ for f := range flen {
if dataset.Columns[f].Len() > r {
row[f] = dataset.Columns[f].Records[r]
} else {
@@ -526,7 +519,7 @@ func (dataset *Dataset) FillRowsWithColumn(colIdx int, col Column) {
for ; y < nrow; y++ {
row := make(Row, ncol)
- for z := 0; z < ncol; z++ {
+ for z := range ncol {
if z == colIdx {
row[colIdx] = col.Records[y]
} else {
@@ -591,18 +584,15 @@ func (dataset *Dataset) PushColumnToRows(col Column) {
// If no existing rows in dataset, initialize the rows slice.
dataset.Rows = make(Rows, colsize)
- for nrow = 0; nrow < colsize; nrow++ {
+ for nrow = range colsize {
row := make(Row, 0)
dataset.Rows[nrow] = &row
}
+ nrow++
}
// Pick the minimum length between column or current row length.
- minrow := nrow
-
- if colsize < nrow {
- minrow = colsize
- }
+ minrow := min(colsize, nrow)
// Push each record in column to each rows
var row *Row
diff --git a/lib/tabula/datasetinterface.go b/lib/tabula/datasetinterface.go
index d695fbc2..77cb8904 100644
--- a/lib/tabula/datasetinterface.go
+++ b/lib/tabula/datasetinterface.go
@@ -7,6 +7,7 @@ package tabula
import (
"encoding/json"
"os"
+ "slices"
)
// DatasetInterface is the interface for working with DSV data.
@@ -191,12 +192,9 @@ func SplitRowsByCategorical(di DatasetInterface, colidx int, splitVal []string)
for _, row := range *di.GetRows() {
found := false
- for _, val := range splitVal {
- if (*row)[colidx].String() == val {
- splitIn.PushRow(row)
- found = true
- break
- }
+ if slices.Contains(splitVal, (*row)[colidx].String()) {
+ splitIn.PushRow(row)
+ found = true
}
if !found {
splitEx.PushRow(row)
diff --git a/lib/tabula/rows.go b/lib/tabula/rows.go
index ccba310c..e9c40207 100644
--- a/lib/tabula/rows.go
+++ b/lib/tabula/rows.go
@@ -9,6 +9,7 @@ import (
"fmt"
"log"
"math/big"
+ "slices"
)
// Rows represent slice of Row.
@@ -141,13 +142,7 @@ func (rows *Rows) RandomPick(n int, duplicate bool) (
}
// check if its already picked
- isPicked := false
- for _, pastIdx := range pickedIdx {
- if idx == pastIdx {
- isPicked = true
- break
- }
- }
+ isPicked := slices.Contains(pickedIdx, idx)
// get another random idx again
if isPicked {
continue
@@ -166,13 +161,7 @@ func (rows *Rows) RandomPick(n int, duplicate bool) (
// select unpicked rows using picked index.
for rid := range *rows {
// check if row index has been picked up
- isPicked := false
- for _, idx := range pickedIdx {
- if rid == idx {
- isPicked = true
- break
- }
- }
+ isPicked := slices.Contains(pickedIdx, rid)
if !isPicked {
unpicked.PushBack((*rows)[rid])
unpickedIdx = append(unpickedIdx, rid)
diff --git a/lib/tabula/rows_test.go b/lib/tabula/rows_test.go
index 82ddc517..af6552f1 100644
--- a/lib/tabula/rows_test.go
+++ b/lib/tabula/rows_test.go
@@ -112,7 +112,7 @@ func TestRandomPick(t *testing.T) {
}
// random pick with duplicate
- for i := 0; i < 5; i++ {
+ for range 5 {
picked, unpicked, pickedIdx, unpickedIdx := rows.RandomPick(6,
true)
@@ -130,7 +130,7 @@ func TestRandomPick(t *testing.T) {
}
// random pick without duplication
- for i := 0; i < 5; i++ {
+ for range 5 {
picked, unpicked, pickedIdx, unpickedIdx := rows.RandomPick(3,
false)
diff --git a/lib/tabula/tabula_test.go b/lib/tabula/tabula_test.go
index 26f0d34f..a4e105b8 100644
--- a/lib/tabula/tabula_test.go
+++ b/lib/tabula/tabula_test.go
@@ -39,7 +39,7 @@ func initRows() (rows Rows, e error) {
l := len(rowsData[i])
row := make(Row, 0)
- for j := 0; j < l; j++ {
+ for j := range l {
rec, e := NewRecordBy(rowsData[i][j],
testColTypes[j])