aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-09-10 23:30:19 +0700
committerShulhan <ms@kilabit.info>2023-09-11 02:26:33 +0700
commite28e7c4347fa2a286a63ea7ce2cc00c696a5b047 (patch)
treeb188f2dfbf51f0cecb2e4b4f603c4b71ca7dc438
parent7fe6bf7036b3b1f97be81f29f2b29d79485e2e08 (diff)
downloadpakakeh.go-e28e7c4347fa2a286a63ea7ce2cc00c696a5b047.tar.xz
lib/tabula: realign struct for better size allocation
The realignment reduce the cost of the following struct, * Claset: from 136 to 120 bytes (-16) * Column: from 64 to 48 bytes (-16) * Dataset: from 40 to 32 bytes (-8) While at it, fix linter warnings due to unused parameters in test.
-rw-r--r--lib/tabula/claset.go19
-rw-r--r--lib/tabula/column.go12
-rw-r--r--lib/tabula/dataset.go6
-rw-r--r--lib/tabula/dataset_test.go8
4 files changed, 27 insertions, 18 deletions
diff --git a/lib/tabula/claset.go b/lib/tabula/claset.go
index 406037d6..8bb4a9ae 100644
--- a/lib/tabula/claset.go
+++ b/lib/tabula/claset.go
@@ -14,20 +14,23 @@ import (
// Claset define a dataset with class attribute.
type Claset struct {
- // Dataset embedded, for implementing the dataset interface.
- Dataset
- // ClassIndex contain index for target classification in columns.
- ClassIndex int `json:"ClassIndex"`
+ // major contain the name of majority class in dataset.
+ major string
+
+ // minor contain the name of minority class in dataset.
+ minor string
// vs contain a copy of value space.
vs []string
+
// counts number of value space in current set.
counts []int
- // major contain the name of majority class in dataset.
- major string
- // minor contain the name of minority class in dataset.
- minor string
+ // Dataset embedded, for implementing the dataset interface.
+ Dataset
+
+ // ClassIndex contain index for target classification in columns.
+ ClassIndex int `json:"ClassIndex"`
}
// NewClaset create and return new Claset object.
diff --git a/lib/tabula/column.go b/lib/tabula/column.go
index b59a53e5..091d6ad5 100644
--- a/lib/tabula/column.go
+++ b/lib/tabula/column.go
@@ -12,15 +12,19 @@ import (
type Column struct {
// Name of column. String identifier for the column.
Name string
+
+ // ValueSpace contain the possible value in records
+ ValueSpace []string
+
+ // Records contain column data.
+ Records Records
+
// Type of column. All record in column have the same type.
Type int
+
// Flag additional attribute that can be set to mark some value on this
// column
Flag int
- // ValueSpace contain the possible value in records
- ValueSpace []string
- // Records contain column data.
- Records Records
}
// NewColumn return new column with type and name.
diff --git a/lib/tabula/dataset.go b/lib/tabula/dataset.go
index bd0bfca2..dfcc11be 100644
--- a/lib/tabula/dataset.go
+++ b/lib/tabula/dataset.go
@@ -33,12 +33,14 @@ var (
// Dataset contain the data, mode of saved data, number of columns and rows in
// data.
type Dataset struct {
- // Mode define the numeric value of output mode.
- Mode int
// Columns is input data that has been parsed.
Columns Columns
+
// Rows is input data that has been parsed.
Rows Rows
+
+ // Mode define the numeric value of output mode.
+ Mode int
}
// NewDataset create new dataset, use the mode to initialize the dataset.
diff --git a/lib/tabula/dataset_test.go b/lib/tabula/dataset_test.go
index 68598deb..9c45ce81 100644
--- a/lib/tabula/dataset_test.go
+++ b/lib/tabula/dataset_test.go
@@ -82,21 +82,21 @@ func createDataset(t *testing.T) (dataset *Dataset) {
return
}
-func DatasetStringJoinByIndex(t *testing.T, dataset [][]string, indis []int) (res string) {
+func DatasetStringJoinByIndex(_ *testing.T, dataset [][]string, indis []int) (res string) {
for x := range indis {
res += fmt.Sprint("&", dataset[indis[x]])
}
return res
}
-func DatasetRowsJoin(t *testing.T) (s string) {
+func DatasetRowsJoin(_ *testing.T) (s string) {
for x := range datasetRows {
s += fmt.Sprint("&", datasetRows[x])
}
return
}
-func DatasetColumnsJoin(t *testing.T) (s string) {
+func DatasetColumnsJoin(_ *testing.T) (s string) {
for x := range datasetCols {
s += fmt.Sprint(datasetCols[x])
}
@@ -205,7 +205,7 @@ func TestModeRowsPushColumn(t *testing.T) {
test.Assert(t, "", exp, got)
// Check columns
- exp = "[{int 1 0 [] []} {real 2 0 [] []} {string 0 0 [] []}]"
+ exp = `[{int [] [] 1 0} {real [] [] 2 0} {string [] [] 0 0}]`
got = fmt.Sprint(dataset.Columns)
test.Assert(t, "", exp, got)