Skip to content

Commit

Permalink
Doc for overloaded function and format
Browse files Browse the repository at this point in the history
  • Loading branch information
amol- committed Nov 28, 2024
1 parent 9c78c90 commit 96978e4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
37 changes: 24 additions & 13 deletions cpp/src/arrow/array/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,9 @@ Result<std::shared_ptr<Array>> MakeMaskArray(const std::vector<int64_t>& indices
}

template <typename IndexType>
Result<std::shared_ptr<Array>> MakeMaskArrayImpl(const std::shared_ptr<NumericArray<IndexType>> &indices,
int64_t length, MemoryPool* pool) {
Result<std::shared_ptr<Array>> MakeMaskArrayImpl(
const std::shared_ptr<NumericArray<IndexType>>& indices, int64_t length,
MemoryPool* pool) {
ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateBitmap(length, pool));
bit_util::SetBitsTo(buffer->mutable_data(), 0, length, false);
for (int64_t i = 0; i < indices->length(); ++i) {
Expand All @@ -941,30 +942,40 @@ Result<std::shared_ptr<Array>> MakeMaskArrayImpl(const std::shared_ptr<NumericAr
return std::make_shared<BooleanArray>(length, buffer);
}

Result<std::shared_ptr<Array>> MakeMaskArray(const std::shared_ptr<Array> &indices,
int64_t length,
MemoryPool* pool) {
Result<std::shared_ptr<Array>> MakeMaskArray(const std::shared_ptr<Array>& indices,
int64_t length, MemoryPool* pool) {
if (indices->null_count() > 0) {
return Status::Invalid("Indices array must not contain null values");
}

switch (indices->type_id()) {
case Type::INT8:
return MakeMaskArrayImpl(internal::checked_pointer_cast<NumericArray<Int8Type>>(indices), length, pool);
return MakeMaskArrayImpl(
internal::checked_pointer_cast<NumericArray<Int8Type>>(indices), length, pool);
case Type::UINT8:
return MakeMaskArrayImpl(internal::checked_pointer_cast<NumericArray<UInt8Type>>(indices), length, pool);
return MakeMaskArrayImpl(
internal::checked_pointer_cast<NumericArray<UInt8Type>>(indices), length, pool);
case Type::INT16:
return MakeMaskArrayImpl(internal::checked_pointer_cast<NumericArray<Int16Type>>(indices), length, pool);
return MakeMaskArrayImpl(
internal::checked_pointer_cast<NumericArray<Int16Type>>(indices), length, pool);
case Type::UINT16:
return MakeMaskArrayImpl(internal::checked_pointer_cast<NumericArray<UInt16Type>>(indices), length, pool);
return MakeMaskArrayImpl(
internal::checked_pointer_cast<NumericArray<UInt16Type>>(indices), length,
pool);
case Type::INT32:
return MakeMaskArrayImpl(internal::checked_pointer_cast<NumericArray<Int32Type>>(indices), length, pool);
return MakeMaskArrayImpl(
internal::checked_pointer_cast<NumericArray<Int32Type>>(indices), length, pool);
case Type::UINT32:
return MakeMaskArrayImpl(internal::checked_pointer_cast<NumericArray<UInt32Type>>(indices), length, pool);
return MakeMaskArrayImpl(
internal::checked_pointer_cast<NumericArray<UInt32Type>>(indices), length,
pool);
case Type::INT64:
return MakeMaskArrayImpl(internal::checked_pointer_cast<NumericArray<Int64Type>>(indices), length, pool);
return MakeMaskArrayImpl(
internal::checked_pointer_cast<NumericArray<Int64Type>>(indices), length, pool);
case Type::UINT64:
return MakeMaskArrayImpl(internal::checked_pointer_cast<NumericArray<UInt64Type>>(indices), length, pool);
return MakeMaskArrayImpl(
internal::checked_pointer_cast<NumericArray<UInt64Type>>(indices), length,
pool);
default:
return Status::Invalid("Indices array must be of integer type");
}
Expand Down
13 changes: 11 additions & 2 deletions cpp/src/arrow/array/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,18 @@ Result<std::shared_ptr<Array>> MakeMaskArray(const std::vector<int64_t>& indices
int64_t length,
MemoryPool* pool = default_memory_pool());

/// \brief Create an Array representing a boolean mask
///
/// The mask will have all elements set to false except for those
/// indices specified in the indices vector.
///
/// \param[in] indices Which indices in the mask should be set to true
/// \param[in] length The total length of the mask
/// \param[in] pool the memory pool to allocate memory from
/// \return the resulting Array
ARROW_EXPORT
Result<std::shared_ptr<Array>> MakeMaskArray(const std::shared_ptr<Array> &indices,
int64_t length,
Result<std::shared_ptr<Array>> MakeMaskArray(const std::shared_ptr<Array>& indices,
int64_t length,
MemoryPool* pool = default_memory_pool());
/// @}

Expand Down

0 comments on commit 96978e4

Please sign in to comment.