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)
| 307 | // given list of column indexes, using either ascending or descending order for |
| 308 | // all of the columns. Only valid for 1-dimensional columns. |
| 309 | func (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 |
no test coverage detected