@@ -1192,11 +1192,50 @@ MutableColumns ColumnObject::scatter(ColumnIndex num_columns, const Selector & s
11921192 return result_columns;
11931193}
11941194
1195- void ColumnObject::getPermutation (PermutationSortDirection, PermutationSortStability, size_t , int , Permutation & res) const
1195+ struct ColumnObject ::ComparatorBase
11961196{
1197- // / Values in ColumnObject are not comparable.
1198- res.resize (size ());
1199- iota (res.data (), res.size (), size_t (0 ));
1197+ const ColumnObject & parent;
1198+ int nan_direction_hint;
1199+
1200+ ComparatorBase (const ColumnObject & parent_, int nan_direction_hint_)
1201+ : parent(parent_), nan_direction_hint(nan_direction_hint_)
1202+ {
1203+ }
1204+
1205+ ALWAYS_INLINE int compare (size_t lhs, size_t rhs) const
1206+ {
1207+ int res = parent.compareAt (lhs, rhs, parent, nan_direction_hint);
1208+
1209+ return res;
1210+ }
1211+ };
1212+
1213+ void ColumnObject::getPermutation (PermutationSortDirection direction, PermutationSortStability stability,
1214+ size_t limit, int nan_direction_hint, Permutation & res) const
1215+ {
1216+ if (direction == IColumn::PermutationSortDirection::Ascending && stability == IColumn::PermutationSortStability::Unstable)
1217+ getPermutationImpl (limit, res, ComparatorAscendingUnstable (*this , nan_direction_hint), DefaultSort (), DefaultPartialSort ());
1218+ else if (direction == IColumn::PermutationSortDirection::Ascending && stability == IColumn::PermutationSortStability::Stable)
1219+ getPermutationImpl (limit, res, ComparatorAscendingStable (*this , nan_direction_hint), DefaultSort (), DefaultPartialSort ());
1220+ else if (direction == IColumn::PermutationSortDirection::Descending && stability == IColumn::PermutationSortStability::Unstable)
1221+ getPermutationImpl (limit, res, ComparatorDescendingUnstable (*this , nan_direction_hint), DefaultSort (), DefaultPartialSort ());
1222+ else if (direction == IColumn::PermutationSortDirection::Descending && stability == IColumn::PermutationSortStability::Stable)
1223+ getPermutationImpl (limit, res, ComparatorDescendingStable (*this , nan_direction_hint), DefaultSort (), DefaultPartialSort ());
1224+ }
1225+
1226+ void ColumnObject::updatePermutation (PermutationSortDirection direction, PermutationSortStability stability,
1227+ size_t limit, int nan_direction_hint, Permutation & res, EqualRanges & equal_ranges) const
1228+ {
1229+ auto comparator_equal = ComparatorEqual (*this , nan_direction_hint);
1230+
1231+ if (direction == IColumn::PermutationSortDirection::Ascending && stability == IColumn::PermutationSortStability::Unstable)
1232+ updatePermutationImpl (limit, res, equal_ranges, ComparatorAscendingUnstable (*this , nan_direction_hint), comparator_equal, DefaultSort (), DefaultPartialSort ());
1233+ else if (direction == IColumn::PermutationSortDirection::Ascending && stability == IColumn::PermutationSortStability::Stable)
1234+ updatePermutationImpl (limit, res, equal_ranges, ComparatorAscendingStable (*this , nan_direction_hint), comparator_equal, DefaultSort (), DefaultPartialSort ());
1235+ else if (direction == IColumn::PermutationSortDirection::Descending && stability == IColumn::PermutationSortStability::Unstable)
1236+ updatePermutationImpl (limit, res, equal_ranges, ComparatorDescendingUnstable (*this , nan_direction_hint), comparator_equal, DefaultSort (), DefaultPartialSort ());
1237+ else if (direction == IColumn::PermutationSortDirection::Descending && stability == IColumn::PermutationSortStability::Stable)
1238+ updatePermutationImpl (limit, res, equal_ranges, ComparatorDescendingStable (*this , nan_direction_hint), comparator_equal, DefaultSort (), DefaultPartialSort ());
12001239}
12011240
12021241void ColumnObject::reserve (size_t n)
0 commit comments