Skip to content

Commit

Permalink
Apply suggestion of using a regular method
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Nov 26, 2024
1 parent c85bb4c commit 13e5cc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
9 changes: 3 additions & 6 deletions cpp/src/arrow/compute/kernels/vector_sort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ class ChunkedArraySorter : public TypeVisitor {

std::vector<ChunkedNullPartitionResult> chunk_sorted(num_chunks);
for (int i = 0; i < num_chunks; ++i) {
chunk_sorted[i] = ChunkedNullPartitionResult::TranslateFrom(
sorted[i], indices_begin_, chunked_indices_begin);
chunk_sorted[i] = sorted[i].TranslateTo(indices_begin_, chunked_indices_begin);
}

auto merge_nulls = [&](CompressedChunkLocation* nulls_begin,
Expand Down Expand Up @@ -158,8 +157,7 @@ class ChunkedArraySorter : public TypeVisitor {

// Reverse everything
sorted.resize(1);
sorted[0] = NullPartitionResult::TranslateFrom(
chunk_sorted[0], chunked_indices_begin, indices_begin_);
sorted[0] = chunk_sorted[0].TranslateTo(chunked_indices_begin, indices_begin_);

RETURN_NOT_OK(chunked_mapper.PhysicalToLogical());
}
Expand Down Expand Up @@ -706,8 +704,7 @@ class TableSorter {

std::vector<ChunkedNullPartitionResult> chunk_sorted(num_batches);
for (int64_t i = 0; i < num_batches; ++i) {
chunk_sorted[i] = ChunkedNullPartitionResult::TranslateFrom(
sorted[i], indices_begin_, chunked_indices_begin);
chunk_sorted[i] = sorted[i].TranslateTo(indices_begin_, chunked_indices_begin);
}

struct Visitor {
Expand Down
15 changes: 7 additions & 8 deletions cpp/src/arrow/compute/kernels/vector_sort_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,14 @@ struct GenericNullPartitionResult {
return {midpoint, indices_end, indices_begin, midpoint};
}

template <typename SourceIndexType>
static GenericNullPartitionResult TranslateFrom(
GenericNullPartitionResult<SourceIndexType> source,
SourceIndexType* source_indices_begin, IndexType* target_indices_begin) {
template <typename TargetIndexType>
GenericNullPartitionResult<TargetIndexType> TranslateTo(
IndexType* indices_begin, TargetIndexType* target_indices_begin) const {
return {
(source.non_nulls_begin - source_indices_begin) + target_indices_begin,
(source.non_nulls_end - source_indices_begin) + target_indices_begin,
(source.nulls_begin - source_indices_begin) + target_indices_begin,
(source.nulls_end - source_indices_begin) + target_indices_begin,
(non_nulls_begin - indices_begin) + target_indices_begin,
(non_nulls_end - indices_begin) + target_indices_begin,
(nulls_begin - indices_begin) + target_indices_begin,
(nulls_end - indices_begin) + target_indices_begin,
};
}
};
Expand Down

0 comments on commit 13e5cc2

Please sign in to comment.