MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / compute_sort_order

Function compute_sort_order

nodedb/src/engine/timeseries/projection.rs:29–50  ·  view source on GitHub ↗

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],
)

Source from the content-addressed store, hash-verified

27/// Returns a permutation vector: `result[i]` is the original row index
28/// that should appear at position `i` in the sorted output.
29pub 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.
53pub fn apply_permutation(data: &ColumnData, perm: &[usize]) -> ColumnData {

Calls 4

compare_column_valuesFunction · 0.85
collectMethod · 0.80
iterMethod · 0.45
getMethod · 0.45

Tested by 2