Skip to content

Commit

Permalink
ree_util: Add CompareValuesAt to ReadWriteValue
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrv committed Apr 10, 2023
1 parent c3db551 commit 6cf6c26
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cpp/src/arrow/compute/kernels/ree_util_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ class ReadWriteValue<ArrowType, in_has_validity_buffer, out_has_validity_buffer,
return valid;
}

/// Pre-conditions guaranteed by the callers:
/// - i and j are valid indices into the values buffer
/// - the values in i and j are valid
bool CompareValuesAt(int64_t i, int64_t j) const {
if constexpr (std::is_same_v<ArrowType, BooleanType>) {
return bit_util::GetBit(input_values_, i) == bit_util::GetBit(input_values_, j);
} else {
return (reinterpret_cast<const ValueRepr*>(input_values_))[i] ==
(reinterpret_cast<const ValueRepr*>(input_values_))[j];
}
}

/// \brief Ensure padding is zeroed in validity bitmap.
void ZeroValidityPadding(int64_t length) const {
DCHECK(output_values_);
Expand Down Expand Up @@ -164,6 +176,11 @@ class ReadWriteValue<ArrowType, in_has_validity_buffer, out_has_validity_buffer,
return valid;
}

bool CompareValuesAt(int64_t i, int64_t j) const {
return 0 == memcmp(input_values_ + (i * byte_width_),
input_values_ + (j * byte_width_), byte_width_);
}

/// \brief Ensure padding is zeroed in validity bitmap.
void ZeroValidityPadding(int64_t length) const {
DCHECK(output_values_);
Expand Down Expand Up @@ -251,6 +268,14 @@ class ReadWriteValue<ArrowType, in_has_validity_buffer, out_has_validity_buffer,
return valid;
}

bool CompareValuesAt(int64_t i, int64_t j) const {
const offset_type len_i = input_offsets_[i + 1] - input_offsets_[i];
const offset_type len_j = input_offsets_[j + 1] - input_offsets_[j];
return len_i == len_j &&
memcmp(input_values_ + input_offsets_[i], input_values_ + input_offsets_[j],
static_cast<size_t>(len_i));
}

/// \brief Ensure padding is zeroed in validity bitmap.
void ZeroValidityPadding(int64_t length) const {
DCHECK(output_values_);
Expand Down

0 comments on commit 6cf6c26

Please sign in to comment.