Skip to content

Commit eefc4d4

Browse files
committed
replace another struct with NullLikePartition
1 parent 9e68728 commit eefc4d4

1 file changed

Lines changed: 10 additions & 22 deletions

File tree

cpp/src/arrow/compute/kernels/vector_select_k.cc

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,10 @@ class SelectKComparator<SortOrder::Descending> {
7676
}
7777
};
7878

79-
struct OutputRangesByNullLikeness {
80-
std::span<uint64_t> non_null_like_range;
81-
std::span<uint64_t> nan_range;
82-
std::span<uint64_t> null_range;
83-
};
84-
85-
OutputRangesByNullLikeness CalculateOutputRangesByNullLikeness(
79+
// Clip the group counts to the k output slots and lay out the corresponding
80+
// ranges in `output_indices`. Because k was clipped to the input length, the
81+
// clipped counts always sum to k == output_indices.size().
82+
NullLikePartition CalculateOutputRangesByNullLikeness(
8683
int64_t non_null_like_count, int64_t nan_count, int64_t null_count,
8784
NullPlacement null_placement, std::span<uint64_t> output_indices) {
8885
auto k = static_cast<int64_t>(output_indices.size());
@@ -93,21 +90,13 @@ OutputRangesByNullLikeness CalculateOutputRangesByNullLikeness(
9390
non_null_like_to_take = std::min(k, non_null_like_count);
9491
nan_to_take = std::min(k - non_null_like_to_take, nan_count);
9592
null_to_take = std::min(k - non_null_like_to_take - nan_to_take, null_count);
96-
return OutputRangesByNullLikeness{
97-
.non_null_like_range = output_indices.subspan(0, non_null_like_to_take),
98-
.nan_range = output_indices.subspan(non_null_like_to_take, nan_to_take),
99-
.null_range =
100-
output_indices.subspan(non_null_like_to_take + nan_to_take, null_to_take)};
10193
} else {
10294
null_to_take = std::min(k, null_count);
10395
nan_to_take = std::min(k - null_to_take, nan_count);
10496
non_null_like_to_take = std::min(k - null_to_take - nan_to_take, non_null_like_count);
105-
return OutputRangesByNullLikeness{
106-
.non_null_like_range =
107-
output_indices.subspan(null_to_take + nan_to_take, non_null_like_to_take),
108-
.nan_range = output_indices.subspan(null_to_take, nan_to_take),
109-
.null_range = output_indices.subspan(0, null_to_take)};
11097
}
98+
return NullLikePartition::FromCounts(output_indices, non_null_like_to_take, nan_to_take,
99+
null_to_take, null_placement);
111100
}
112101

113102
template <typename Comparator>
@@ -226,10 +215,9 @@ class ArraySelector : public TypeVisitor {
226215

227216
HeapSortNonNullsToOutput<InType, sort_order>(p.non_null_like_range, arr,
228217
output.non_null_like_range);
229-
std::copy(p.nan_begin(), p.nan_begin() + output.nan_range.size(),
230-
output.nan_range.begin());
218+
std::copy(p.nan_begin(), p.nan_begin() + output.nan_range.size(), output.nan_begin());
231219
std::copy(p.null_begin(), p.null_begin() + output.null_range.size(),
232-
output.null_range.begin());
220+
output.null_begin());
233221

234222
*output_ = Datum(take_indices);
235223
return Status::OK();
@@ -493,12 +481,12 @@ class RecordBatchSelector {
493481
if (output.nan_range.size() > 0) {
494482
// We have the last sort_key, can just copy over the null values
495483
std::copy(p.nan_begin(), p.nan_begin() + output.nan_range.size(),
496-
output.nan_range.begin());
484+
output.nan_begin());
497485
}
498486
if (output.null_range.size() > 0) {
499487
// We have the last sort_key, can just copy over the null values
500488
std::copy(p.null_begin(), p.null_begin() + output.null_range.size(),
501-
output.null_range.begin());
489+
output.null_begin());
502490
}
503491
} else {
504492
if (!output.non_null_like_range.empty()) {

0 commit comments

Comments
 (0)