MCPcopy Create free account
hub / github.com/cogentcore/core / SortColumn

Method SortColumn

tensor/table/indexview.go:149–168  ·  view source on GitHub ↗

SortColumn sorts the indexes into our Table according to values in given column index, using either ascending or descending order. Only valid for 1-dimensional columns.

(colIndex int, ascending bool)

Source from the content-addressed store, hash-verified

147// given column index, using either ascending or descending order.
148// Only valid for 1-dimensional columns.
149func (ix *IndexView) SortColumn(colIndex int, ascending bool) {
150 cl := ix.Table.Columns[colIndex]
151 if cl.IsString() {
152 ix.Sort(func(et *Table, i, j int) bool {
153 if ascending {
154 return cl.String1D(i) < cl.String1D(j)
155 } else {
156 return cl.String1D(i) > cl.String1D(j)
157 }
158 })
159 } else {
160 ix.Sort(func(et *Table, i, j int) bool {
161 if ascending {
162 return cl.Float1D(i) < cl.Float1D(j)
163 } else {
164 return cl.Float1D(i) > cl.Float1D(j)
165 }
166 })
167 }
168}
169
170// SortColumnNames sorts the indexes into our Table according to values in
171// given column names, using either ascending or descending order.

Callers 3

SortColumnNameMethod · 0.95
SortSliceActionMethod · 0.45
QuantilesIndexFunction · 0.45

Calls 4

SortMethod · 0.95
IsStringMethod · 0.65
String1DMethod · 0.65
Float1DMethod · 0.65

Tested by

no test coverage detected