SortStableColumn 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)
| 261 | // given column index, using either ascending or descending order. |
| 262 | // Only valid for 1-dimensional columns. |
| 263 | func (ix *IndexView) SortStableColumn(colIndex int, ascending bool) { |
| 264 | cl := ix.Table.Columns[colIndex] |
| 265 | if cl.IsString() { |
| 266 | ix.SortStable(func(et *Table, i, j int) bool { |
| 267 | if ascending { |
| 268 | return cl.String1D(i) < cl.String1D(j) |
| 269 | } else { |
| 270 | return cl.String1D(i) > cl.String1D(j) |
| 271 | } |
| 272 | }) |
| 273 | } else { |
| 274 | ix.SortStable(func(et *Table, i, j int) bool { |
| 275 | if ascending { |
| 276 | return cl.Float1D(i) < cl.Float1D(j) |
| 277 | } else { |
| 278 | return cl.Float1D(i) > cl.Float1D(j) |
| 279 | } |
| 280 | }) |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | // SortStableColumnNames sorts the indexes into our Table according to values in |
| 285 | // given column names, using either ascending or descending order. |
no test coverage detected