Sort indices for a projection. Returns a permutation vector: `result[i]` is the original row index that should appear at position `i` in the sorted output.
(
drain: &ColumnarDrainResult,
sort_columns: &[usize],
ascending: &[bool],
)
| 27 | /// Returns a permutation vector: `result[i]` is the original row index |
| 28 | /// that should appear at position `i` in the sorted output. |
| 29 | pub fn compute_sort_order( |
| 30 | drain: &ColumnarDrainResult, |
| 31 | sort_columns: &[usize], |
| 32 | ascending: &[bool], |
| 33 | ) -> Vec<usize> { |
| 34 | let row_count = drain.row_count as usize; |
| 35 | let mut indices: Vec<usize> = (0..row_count).collect(); |
| 36 | |
| 37 | indices.sort_by(|&a, &b| { |
| 38 | for (i, &col_idx) in sort_columns.iter().enumerate() { |
| 39 | let asc = ascending.get(i).copied().unwrap_or(true); |
| 40 | let ord = compare_column_values(&drain.columns[col_idx], a, b); |
| 41 | let ord = if asc { ord } else { ord.reverse() }; |
| 42 | if ord != std::cmp::Ordering::Equal { |
| 43 | return ord; |
| 44 | } |
| 45 | } |
| 46 | std::cmp::Ordering::Equal |
| 47 | }); |
| 48 | |
| 49 | indices |
| 50 | } |
| 51 | |
| 52 | /// Apply a permutation to reorder column data. |
| 53 | pub fn apply_permutation(data: &ColumnData, perm: &[usize]) -> ColumnData { |