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)
| 147 | // given column index, using either ascending or descending order. |
| 148 | // Only valid for 1-dimensional columns. |
| 149 | func (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. |
no test coverage detected