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

Method SortColumns

tensor/table/indexview.go:195–231  ·  view source on GitHub ↗

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

(colIndexes []int, ascending bool)

Source from the content-addressed store, hash-verified

193// given list of column indexes, using either ascending or descending order for
194// all of the columns. Only valid for 1-dimensional columns.
195func (ix *IndexView) SortColumns(colIndexes []int, ascending bool) {
196 ix.Sort(func(et *Table, i, j int) bool {
197 for _, ci := range colIndexes {
198 cl := ix.Table.Columns[ci]
199 if cl.IsString() {
200 if ascending {
201 if cl.String1D(i) < cl.String1D(j) {
202 return true
203 } else if cl.String1D(i) > cl.String1D(j) {
204 return false
205 } // if equal, fallthrough to next col
206 } else {
207 if cl.String1D(i) > cl.String1D(j) {
208 return true
209 } else if cl.String1D(i) < cl.String1D(j) {
210 return false
211 } // if equal, fallthrough to next col
212 }
213 } else {
214 if ascending {
215 if cl.Float1D(i) < cl.Float1D(j) {
216 return true
217 } else if cl.Float1D(i) > cl.Float1D(j) {
218 return false
219 } // if equal, fallthrough to next col
220 } else {
221 if cl.Float1D(i) > cl.Float1D(j) {
222 return true
223 } else if cl.Float1D(i) < cl.Float1D(j) {
224 return false
225 } // if equal, fallthrough to next col
226 }
227 }
228 }
229 return false
230 })
231}
232
233/////////////////////////////////////////////////////////////////////////
234// Stable sorts -- sometimes essential..

Callers 1

SortColumnNamesMethod · 0.95

Calls 4

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

Tested by

no test coverage detected