Skip to content

Commit

Permalink
Clean up template instantiations to fix clang
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Mar 25, 2016
1 parent 2d3b855 commit f6b60f1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 73 deletions.
79 changes: 36 additions & 43 deletions cpp/src/arrow/types/primitive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ Status PrimitiveBuilder<T>::Reserve(int32_t elements) {
}

template <typename T>
std::shared_ptr<Array> NumericBuilder<T>::Finish() {
return PrimitiveBuilder<T>::Finish();
}

template <typename T>
Status NumericBuilder<T>::Append(const value_type* values, int32_t length,
Status PrimitiveBuilder<T>::Append(const value_type* values, int32_t length,
const uint8_t* valid_bytes) {
RETURN_NOT_OK(PrimitiveBuilder<T>::Reserve(length));

Expand Down Expand Up @@ -170,16 +165,41 @@ std::shared_ptr<Array> PrimitiveBuilder<T>::Finish() {
return result;
}

template class NumericBuilder<UInt8Type>;
template class NumericBuilder<UInt16Type>;
template class NumericBuilder<UInt32Type>;
template class NumericBuilder<UInt64Type>;
template class NumericBuilder<Int8Type>;
template class NumericBuilder<Int16Type>;
template class NumericBuilder<Int32Type>;
template class NumericBuilder<Int64Type>;
template class NumericBuilder<FloatType>;
template class NumericBuilder<DoubleType>;
template <>
Status PrimitiveBuilder<BooleanType>::Append(const uint8_t* values, int32_t length,
const uint8_t* valid_bytes) {
RETURN_NOT_OK(Reserve(length));

for (int i = 0; i < length; ++i) {
if (values[i] > 0) {
util::set_bit(raw_data_, length_ + i);
} else {
util::clear_bit(raw_data_, length_ + i);
}
}

if (valid_bytes != nullptr) {
PrimitiveBuilder<BooleanType>::AppendNulls(valid_bytes, length);
} else {
for (int i = 0; i < length; ++i) {
util::set_bit(null_bitmap_data_, length_ + i);
}
}
length_ += length;
return Status::OK();
}

template class PrimitiveBuilder<UInt8Type>;
template class PrimitiveBuilder<UInt16Type>;
template class PrimitiveBuilder<UInt32Type>;
template class PrimitiveBuilder<UInt64Type>;
template class PrimitiveBuilder<Int8Type>;
template class PrimitiveBuilder<Int16Type>;
template class PrimitiveBuilder<Int32Type>;
template class PrimitiveBuilder<Int64Type>;
template class PrimitiveBuilder<FloatType>;
template class PrimitiveBuilder<DoubleType>;
template class PrimitiveBuilder<BooleanType>;

BooleanArray::BooleanArray(int32_t length, const std::shared_ptr<Buffer>& data,
int32_t null_count,
Expand Down Expand Up @@ -222,31 +242,4 @@ bool BooleanArray::Equals(const std::shared_ptr<Array>& arr) const {
return EqualsExact(*static_cast<const BooleanArray*>(arr.get()));
}

Status BooleanBuilder::Append(const uint8_t* values, int32_t length,
const uint8_t* valid_bytes) {
RETURN_NOT_OK(Reserve(length));

for (int i = 0; i < length; ++i) {
if (values[i] > 0) {
util::set_bit(raw_data_, length_ + i);
} else {
util::clear_bit(raw_data_, length_ + i);
}
}

if (valid_bytes != nullptr) {
PrimitiveBuilder<BooleanType>::AppendNulls(valid_bytes, length);
} else {
for (int i = 0; i < length; ++i) {
util::set_bit(null_bitmap_data_, length_ + i);
}
}
length_ += length;
return Status::OK();
}

std::shared_ptr<Array> BooleanBuilder::Finish() {
return PrimitiveBuilder<BooleanType>::Finish();
}

} // namespace arrow
51 changes: 22 additions & 29 deletions cpp/src/arrow/types/primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,19 @@ class PrimitiveBuilder : public ArrayBuilder {
return data_;
}

// Vector append
//
// If passed, valid_bytes is of equal length to values, and any zero byte
// will be considered as a null for that slot
Status Append(const value_type* values, int32_t length,
const uint8_t* valid_bytes = nullptr);

// Ensure that builder can accommodate an additional number of
// elements. Resizes if the current capacity is not sufficient
Status Reserve(int32_t elements);

std::shared_ptr<Array> Finish() override;

protected:
std::shared_ptr<PoolBuffer> data_;
value_type* raw_data_;
Expand All @@ -134,35 +143,29 @@ class PrimitiveBuilder : public ArrayBuilder {
// Increase the capacity of the builder to accommodate at least the indicated
// number of elements
Status Resize(int32_t capacity);

std::shared_ptr<Array> Finish() override;
};

template <typename Type>
class NumericBuilder : public PrimitiveBuilder<Type> {
template <typename T>
class NumericBuilder : public PrimitiveBuilder<T> {
public:
using typename PrimitiveBuilder<Type>::value_type;
using PrimitiveBuilder<Type>::PrimitiveBuilder;
using typename PrimitiveBuilder<T>::value_type;
using PrimitiveBuilder<T>::PrimitiveBuilder;

using PrimitiveBuilder<T>::Append;

// Scalar append. Does not capacity-check; make sure to call Reserve beforehand
void Append(value_type val) {
util::set_bit(null_bitmap_data_, length_);
raw_data_[length_++] = val;
}

// Vector append
//
// If passed, valid_bytes is of equal length to values, and any zero byte
// will be considered as a null for that slot
Status Append(const value_type* values, int32_t length,
const uint8_t* valid_bytes = nullptr);

std::shared_ptr<Array> Finish() override;

protected:
using PrimitiveBuilder<Type>::length_;
using PrimitiveBuilder<Type>::null_bitmap_data_;
using PrimitiveBuilder<Type>::raw_data_;
using PrimitiveBuilder<T>::length_;
using PrimitiveBuilder<T>::null_bitmap_data_;
using PrimitiveBuilder<T>::raw_data_;

using PrimitiveBuilder<T>::Init;
using PrimitiveBuilder<T>::Resize;
};

template <>
Expand Down Expand Up @@ -306,7 +309,7 @@ class BooleanBuilder : public PrimitiveBuilder<BooleanType> {

virtual ~BooleanBuilder() {}

std::shared_ptr<Array> Finish() override;
using PrimitiveBuilder<BooleanType>::Append;

// Scalar append
void Append(bool val) {
Expand All @@ -322,16 +325,6 @@ class BooleanBuilder : public PrimitiveBuilder<BooleanType> {
void Append(uint8_t val) {
Append(static_cast<bool>(val));
}

// Vector append
//
// If passed, valid_bytes is of equal length to values, and any zero byte
// will be considered as a null for that slot
Status Append(const uint8_t* values, int32_t length,
const uint8_t* valid_bytes = nullptr);

Status Append(const std::vector<uint8_t>& values,
const uint8_t* valid_bytes = nullptr);
};

} // namespace arrow
Expand Down
1 change: 0 additions & 1 deletion python/src/pyarrow/adapters/builtin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class TypedConverter : public SeqConverter {
class BoolConverter : public TypedConverter<arrow::BooleanBuilder> {
public:
Status AppendData(PyObject* seq) override {
int64_t val;
Py_ssize_t size = PySequence_Size(seq);
RETURN_ARROW_NOT_OK(typed_builder_->Reserve(size));
for (int64_t i = 0; i < size; ++i) {
Expand Down

0 comments on commit f6b60f1

Please sign in to comment.