Create a new [`RowCollection`] from a collection of [`Row`]s. Sorts data by `order_by`. Note that all row collections to be merged must be constructed with the same `order_by` to ensure a consistent sort order. Anything else is undefined behavior. TODO: Remember the `order_by` and assert that it is the same for all collections.
(mut rows: Vec<(Row, NonZeroUsize)>, order_by: &[ColumnOrder])
| 68 | /// to ensure a consistent sort order. Anything else is undefined behavior. |
| 69 | // TODO: Remember the `order_by` and assert that it is the same for all collections. |
| 70 | pub fn new(mut rows: Vec<(Row, NonZeroUsize)>, order_by: &[ColumnOrder]) -> Self { |
| 71 | let comparator = RowComparator::new(order_by); |
| 72 | // Sort data to maintain sortedness invariants. |
| 73 | rows.sort_by(|(row1, _diff1), (row2, _diff2)| { |
| 74 | comparator.compare_rows(row1, row2, || row1.cmp(row2)) |
| 75 | }); |
| 76 | |
| 77 | // Pre-sizing our buffer should allow us to make just 1 allocation, and |
| 78 | // use the perfect amount of memory. |
| 79 | // |
| 80 | // Note(parkmycar): I didn't do any benchmarking to determine if this |
| 81 | // is faster, so feel free to change this if you'd like. |
| 82 | let encoded_size = rows.iter().map(|(row, _diff)| row.data_len()).sum(); |
| 83 | |
| 84 | let mut builder = Self::builder(encoded_size, rows.len()); |
| 85 | for (row, diff) in rows { |
| 86 | builder.push(row.as_row_ref(), diff); |
| 87 | } |
| 88 | builder.build() |
| 89 | } |
| 90 | |
| 91 | fn iter(&self) -> impl Iterator<Item = (&RowRef, NonZeroUsize)> { |
| 92 | self.rows.iter().zip_eq(self.diffs.iter().copied()) |
nothing calls this directly
no test coverage detected