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

Method SortStableColumns

tensor/table/indexview.go:309–345  ·  view source on GitHub ↗

SortStableColumns 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

307// given list of column indexes, using either ascending or descending order for
308// all of the columns. Only valid for 1-dimensional columns.
309func (ix *IndexView) SortStableColumns(colIndexes []int, ascending bool) {
310 ix.SortStable(func(et *Table, i, j int) bool {
311 for _, ci := range colIndexes {
312 cl := ix.Table.Columns[ci]
313 if cl.IsString() {
314 if ascending {
315 if cl.String1D(i) < cl.String1D(j) {
316 return true
317 } else if cl.String1D(i) > cl.String1D(j) {
318 return false
319 } // if equal, fallthrough to next col
320 } else {
321 if cl.String1D(i) > cl.String1D(j) {
322 return true
323 } else if cl.String1D(i) < cl.String1D(j) {
324 return false
325 } // if equal, fallthrough to next col
326 }
327 } else {
328 if ascending {
329 if cl.Float1D(i) < cl.Float1D(j) {
330 return true
331 } else if cl.Float1D(i) > cl.Float1D(j) {
332 return false
333 } // if equal, fallthrough to next col
334 } else {
335 if cl.Float1D(i) > cl.Float1D(j) {
336 return true
337 } else if cl.Float1D(i) < cl.Float1D(j) {
338 return false
339 } // if equal, fallthrough to next col
340 }
341 }
342 }
343 return false
344 })
345}
346
347// Filter filters the indexes into our Table using given Filter function.
348// The Filter function operates directly on row numbers into the Table

Callers 2

SortStableColumnNamesMethod · 0.95
GroupByIndexFunction · 0.80

Calls 4

SortStableMethod · 0.95
IsStringMethod · 0.65
String1DMethod · 0.65
Float1DMethod · 0.65

Tested by

no test coverage detected