http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/type.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/type.cc b/cpp/src/arrow/type.cc index 623c193..586da2d 100644 --- a/cpp/src/arrow/type.cc +++ b/cpp/src/arrow/type.cc @@ -37,7 +37,7 @@ std::shared_ptr<Field> Field::AddMetadata( } Status Field::AddMetadata(const std::shared_ptr<const KeyValueMetadata>& metadata, - std::shared_ptr<Field>* out) const { + std::shared_ptr<Field>* out) const { *out = AddMetadata(metadata); return Status::OK(); } @@ -47,7 +47,9 @@ std::shared_ptr<Field> Field::RemoveMetadata() const { } bool Field::Equals(const Field& other) const { - if (this == &other) { return true; } + if (this == &other) { + return true; + } if (this->name_ == other.name_ && this->nullable_ == other.nullable_ && this->type_->Equals(*other.type_.get())) { if (metadata_ == nullptr && other.metadata_ == nullptr) { @@ -68,7 +70,9 @@ bool Field::Equals(const std::shared_ptr<Field>& other) const { std::string Field::ToString() const { std::stringstream ss; ss << this->name_ << ": " << this->type_->ToString(); - if (!this->nullable_) { ss << " not null"; } + if (!this->nullable_) { + ss << " not null"; + } return ss.str(); } @@ -77,34 +81,28 @@ DataType::~DataType() {} bool DataType::Equals(const DataType& other) const { bool are_equal = false; Status error = TypeEquals(*this, other, &are_equal); - if (!error.ok()) { DCHECK(false) << "Types not comparable: " << error.ToString(); } + if (!error.ok()) { + DCHECK(false) << "Types not comparable: " << error.ToString(); + } return are_equal; } bool DataType::Equals(const std::shared_ptr<DataType>& other) const { - if (!other) { return false; } + if (!other) { + return false; + } return Equals(*other.get()); } -std::string BooleanType::ToString() const { - return name(); -} +std::string BooleanType::ToString() const { return name(); } -FloatingPoint::Precision HalfFloatType::precision() const { - return FloatingPoint::HALF; -} +FloatingPoint::Precision HalfFloatType::precision() const { return FloatingPoint::HALF; } -FloatingPoint::Precision FloatType::precision() const { - return FloatingPoint::SINGLE; -} +FloatingPoint::Precision FloatType::precision() const { return FloatingPoint::SINGLE; } -FloatingPoint::Precision DoubleType::precision() const { - return FloatingPoint::DOUBLE; -} +FloatingPoint::Precision DoubleType::precision() const { return FloatingPoint::DOUBLE; } -std::string StringType::ToString() const { - return std::string("string"); -} +std::string StringType::ToString() const { return std::string("string"); } std::string ListType::ToString() const { std::stringstream s; @@ -112,13 +110,9 @@ std::string ListType::ToString() const { return s.str(); } -std::string BinaryType::ToString() const { - return std::string("binary"); -} +std::string BinaryType::ToString() const { return std::string("binary"); } -int FixedSizeBinaryType::bit_width() const { - return CHAR_BIT * byte_width(); -} +int FixedSizeBinaryType::bit_width() const { return CHAR_BIT * byte_width(); } std::string FixedSizeBinaryType::ToString() const { std::stringstream ss; @@ -130,7 +124,9 @@ std::string StructType::ToString() const { std::stringstream s; s << "struct<"; for (int i = 0; i < this->num_children(); ++i) { - if (i > 0) { s << ", "; } + if (i > 0) { + s << ", "; + } std::shared_ptr<Field> field = this->child(i); s << field->name() << ": " << field->type()->ToString(); } @@ -148,13 +144,9 @@ Date32Type::Date32Type() : DateType(Type::DATE32, DateUnit::DAY) {} Date64Type::Date64Type() : DateType(Type::DATE64, DateUnit::MILLI) {} -std::string Date64Type::ToString() const { - return std::string("date64[ms]"); -} +std::string Date64Type::ToString() const { return std::string("date64[ms]"); } -std::string Date32Type::ToString() const { - return std::string("date32[day]"); -} +std::string Date32Type::ToString() const { return std::string("date32[day]"); } // ---------------------------------------------------------------------- // Time types @@ -190,7 +182,9 @@ std::string Time64Type::ToString() const { std::string TimestampType::ToString() const { std::stringstream ss; ss << "timestamp[" << this->unit_; - if (this->timezone_.size() > 0) { ss << ", tz=" << this->timezone_; } + if (this->timezone_.size() > 0) { + ss << ", tz=" << this->timezone_; + } ss << "]"; return ss.str(); } @@ -199,7 +193,7 @@ std::string TimestampType::ToString() const { // Union type UnionType::UnionType(const std::vector<std::shared_ptr<Field>>& fields, - const std::vector<uint8_t>& type_codes, UnionMode mode) + const std::vector<uint8_t>& type_codes, UnionMode mode) : NestedType(Type::UNION), mode_(mode), type_codes_(type_codes) { children_ = fields; } @@ -214,7 +208,9 @@ std::string UnionType::ToString() const { } for (size_t i = 0; i < children_.size(); ++i) { - if (i) { s << ", "; } + if (i) { + s << ", "; + } s << children_[i]->ToString() << "=" << static_cast<int>(type_codes_[i]); } s << ">"; @@ -225,7 +221,7 @@ std::string UnionType::ToString() const { // DictionaryType DictionaryType::DictionaryType(const std::shared_ptr<DataType>& index_type, - const std::shared_ptr<Array>& dictionary, bool ordered) + const std::shared_ptr<Array>& dictionary, bool ordered) : FixedWidthType(Type::DICTIONARY), index_type_(index_type), dictionary_(dictionary), @@ -235,9 +231,7 @@ int DictionaryType::bit_width() const { return static_cast<const FixedWidthType*>(index_type_.get())->bit_width(); } -std::shared_ptr<Array> DictionaryType::dictionary() const { - return dictionary_; -} +std::shared_ptr<Array> DictionaryType::dictionary() const { return dictionary_; } std::string DictionaryType::ToString() const { std::stringstream ss; @@ -249,23 +243,27 @@ std::string DictionaryType::ToString() const { // ---------------------------------------------------------------------- // Null type -std::string NullType::ToString() const { - return name(); -} +std::string NullType::ToString() const { return name(); } // ---------------------------------------------------------------------- // Schema implementation Schema::Schema(const std::vector<std::shared_ptr<Field>>& fields, - const std::shared_ptr<const KeyValueMetadata>& metadata) + const std::shared_ptr<const KeyValueMetadata>& metadata) : fields_(fields), metadata_(metadata) {} bool Schema::Equals(const Schema& other) const { - if (this == &other) { return true; } + if (this == &other) { + return true; + } - if (num_fields() != other.num_fields()) { return false; } + if (num_fields() != other.num_fields()) { + return false; + } for (int i = 0; i < num_fields(); ++i) { - if (!field(i)->Equals(*other.field(i).get())) { return false; } + if (!field(i)->Equals(*other.field(i).get())) { + return false; + } } return true; } @@ -290,8 +288,8 @@ int64_t Schema::GetFieldIndex(const std::string& name) const { } } -Status Schema::AddField( - int i, const std::shared_ptr<Field>& field, std::shared_ptr<Schema>* out) const { +Status Schema::AddField(int i, const std::shared_ptr<Field>& field, + std::shared_ptr<Schema>* out) const { DCHECK_GE(i, 0); DCHECK_LE(i, this->num_fields()); @@ -305,7 +303,7 @@ std::shared_ptr<Schema> Schema::AddMetadata( } Status Schema::AddMetadata(const std::shared_ptr<const KeyValueMetadata>& metadata, - std::shared_ptr<Schema>* out) const { + std::shared_ptr<Schema>* out) const { *out = AddMetadata(metadata); return Status::OK(); } @@ -327,7 +325,9 @@ std::string Schema::ToString() const { int i = 0; for (auto field : fields_) { - if (i > 0) { buffer << std::endl; } + if (i > 0) { + buffer << std::endl; + } buffer << field->ToString(); ++i; } @@ -422,18 +422,18 @@ std::shared_ptr<DataType> struct_(const std::vector<std::shared_ptr<Field>>& fie } std::shared_ptr<DataType> union_(const std::vector<std::shared_ptr<Field>>& child_fields, - const std::vector<uint8_t>& type_codes, UnionMode mode) { + const std::vector<uint8_t>& type_codes, UnionMode mode) { return std::make_shared<UnionType>(child_fields, type_codes, mode); } std::shared_ptr<DataType> dictionary(const std::shared_ptr<DataType>& index_type, - const std::shared_ptr<Array>& dict_values) { + const std::shared_ptr<Array>& dict_values) { return std::make_shared<DictionaryType>(index_type, dict_values); } std::shared_ptr<Field> field(const std::string& name, - const std::shared_ptr<DataType>& type, bool nullable, - const std::shared_ptr<const KeyValueMetadata>& metadata) { + const std::shared_ptr<DataType>& type, bool nullable, + const std::shared_ptr<const KeyValueMetadata>& metadata) { return std::make_shared<Field>(name, type, nullable, metadata); } @@ -454,9 +454,7 @@ std::vector<BufferDescr> FixedWidthType::GetBufferLayout() const { return {kValidityBuffer, BufferDescr(BufferType::DATA, bit_width())}; } -std::vector<BufferDescr> NullType::GetBufferLayout() const { - return {}; -} +std::vector<BufferDescr> NullType::GetBufferLayout() const { return {}; } std::vector<BufferDescr> BinaryType::GetBufferLayout() const { return {kValidityBuffer, kOffsetBuffer, kValues8}; @@ -474,9 +472,7 @@ std::vector<BufferDescr> ListType::GetBufferLayout() const { return {kValidityBuffer, kOffsetBuffer}; } -std::vector<BufferDescr> StructType::GetBufferLayout() const { - return {kValidityBuffer}; -} +std::vector<BufferDescr> StructType::GetBufferLayout() const { return {kValidityBuffer}; } std::vector<BufferDescr> UnionType::GetBufferLayout() const { if (mode_ == UnionMode::SPARSE) {
http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/type.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/type.h b/cpp/src/arrow/type.h index fffb840..e0df722 100644 --- a/cpp/src/arrow/type.h +++ b/cpp/src/arrow/type.h @@ -204,15 +204,15 @@ class NoExtraMeta {}; class ARROW_EXPORT Field { public: Field(const std::string& name, const std::shared_ptr<DataType>& type, - bool nullable = true, - const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr) + bool nullable = true, + const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr) : name_(name), type_(type), nullable_(nullable), metadata_(metadata) {} std::shared_ptr<const KeyValueMetadata> metadata() const { return metadata_; } /// \deprecated Status AddMetadata(const std::shared_ptr<const KeyValueMetadata>& metadata, - std::shared_ptr<Field>* out) const; + std::shared_ptr<Field>* out) const; std::shared_ptr<Field> AddMetadata( const std::shared_ptr<const KeyValueMetadata>& metadata) const; @@ -489,7 +489,7 @@ class ARROW_EXPORT UnionType : public NestedType { static constexpr Type::type type_id = Type::UNION; UnionType(const std::vector<std::shared_ptr<Field>>& fields, - const std::vector<uint8_t>& type_codes, UnionMode mode = UnionMode::SPARSE); + const std::vector<uint8_t>& type_codes, UnionMode mode = UnionMode::SPARSE); std::string ToString() const override; static std::string name() { return "union"; } @@ -669,7 +669,7 @@ class ARROW_EXPORT DictionaryType : public FixedWidthType { static constexpr Type::type type_id = Type::DICTIONARY; DictionaryType(const std::shared_ptr<DataType>& index_type, - const std::shared_ptr<Array>& dictionary, bool ordered = false); + const std::shared_ptr<Array>& dictionary, bool ordered = false); int bit_width() const override; @@ -699,7 +699,7 @@ class ARROW_EXPORT DictionaryType : public FixedWidthType { class ARROW_EXPORT Schema { public: explicit Schema(const std::vector<std::shared_ptr<Field>>& fields, - const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr); + const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr); virtual ~Schema() = default; /// Returns true if all of the schema fields are equal @@ -724,13 +724,13 @@ class ARROW_EXPORT Schema { /// \brief Render a string representation of the schema suitable for debugging std::string ToString() const; - Status AddField( - int i, const std::shared_ptr<Field>& field, std::shared_ptr<Schema>* out) const; + Status AddField(int i, const std::shared_ptr<Field>& field, + std::shared_ptr<Schema>* out) const; Status RemoveField(int i, std::shared_ptr<Schema>* out) const; /// \deprecated Status AddMetadata(const std::shared_ptr<const KeyValueMetadata>& metadata, - std::shared_ptr<Schema>* out) const; + std::shared_ptr<Schema>* out) const; /// \brief Replace key-value metadata with new metadata /// @@ -761,8 +761,8 @@ std::shared_ptr<DataType> ARROW_EXPORT list(const std::shared_ptr<Field>& value_ std::shared_ptr<DataType> ARROW_EXPORT list(const std::shared_ptr<DataType>& value_type); std::shared_ptr<DataType> ARROW_EXPORT timestamp(TimeUnit::type unit); -std::shared_ptr<DataType> ARROW_EXPORT timestamp( - TimeUnit::type unit, const std::string& timezone); +std::shared_ptr<DataType> ARROW_EXPORT timestamp(TimeUnit::type unit, + const std::string& timezone); /// Unit can be either SECOND or MILLI std::shared_ptr<DataType> ARROW_EXPORT time32(TimeUnit::type unit); @@ -770,18 +770,18 @@ std::shared_ptr<DataType> ARROW_EXPORT time32(TimeUnit::type unit); /// Unit can be either MICRO or NANO std::shared_ptr<DataType> ARROW_EXPORT time64(TimeUnit::type unit); -std::shared_ptr<DataType> ARROW_EXPORT struct_( - const std::vector<std::shared_ptr<Field>>& fields); +std::shared_ptr<DataType> ARROW_EXPORT +struct_(const std::vector<std::shared_ptr<Field>>& fields); -std::shared_ptr<DataType> ARROW_EXPORT union_( - const std::vector<std::shared_ptr<Field>>& child_fields, - const std::vector<uint8_t>& type_codes, UnionMode mode = UnionMode::SPARSE); +std::shared_ptr<DataType> ARROW_EXPORT +union_(const std::vector<std::shared_ptr<Field>>& child_fields, + const std::vector<uint8_t>& type_codes, UnionMode mode = UnionMode::SPARSE); std::shared_ptr<DataType> ARROW_EXPORT dictionary( const std::shared_ptr<DataType>& index_type, const std::shared_ptr<Array>& values); -std::shared_ptr<Field> ARROW_EXPORT field(const std::string& name, - const std::shared_ptr<DataType>& type, bool nullable = true, +std::shared_ptr<Field> ARROW_EXPORT field( + const std::string& name, const std::shared_ptr<DataType>& type, bool nullable = true, const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr); // ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/type_traits.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/type_traits.h b/cpp/src/arrow/type_traits.h index 3e8ea23..8be67b2 100644 --- a/cpp/src/arrow/type_traits.h +++ b/cpp/src/arrow/type_traits.h @@ -319,9 +319,10 @@ GET_ATTR(TypeClass, void); #undef GET_ATTR -#define PRIMITIVE_TRAITS(T) \ - using TypeClass = typename std::conditional<std::is_base_of<DataType, T>::value, T, \ - typename GetAttr_TypeClass<T>::type>::type; \ +#define PRIMITIVE_TRAITS(T) \ + using TypeClass = \ + typename std::conditional<std::is_base_of<DataType, T>::value, T, \ + typename GetAttr_TypeClass<T>::type>::type; \ using c_type = typename GetAttr_c_type<TypeClass>::type; template <typename T> http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/bit-stream-utils.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/bit-stream-utils.h b/cpp/src/arrow/util/bit-stream-utils.h index 537fdc3..318f5ba 100644 --- a/cpp/src/arrow/util/bit-stream-utils.h +++ b/cpp/src/arrow/util/bit-stream-utils.h @@ -20,9 +20,9 @@ #ifndef ARROW_UTIL_BIT_STREAM_UTILS_H #define ARROW_UTIL_BIT_STREAM_UTILS_H +#include <string.h> #include <algorithm> #include <cstdint> -#include <string.h> #include "arrow/util/bit-util.h" #include "arrow/util/bpacking.h" @@ -229,13 +229,13 @@ inline bool BitWriter::PutVlqInt(uint32_t v) { template <typename T> inline void GetValue_(int num_bits, T* v, int max_bytes, const uint8_t* buffer, - int* bit_offset, int* byte_offset, uint64_t* buffered_values) { + int* bit_offset, int* byte_offset, uint64_t* buffered_values) { #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4800) #endif - *v = static_cast<T>( - BitUtil::TrailingBits(*buffered_values, *bit_offset + num_bits) >> *bit_offset); + *v = static_cast<T>(BitUtil::TrailingBits(*buffered_values, *bit_offset + num_bits) >> + *bit_offset); #ifdef _MSC_VER #pragma warning(pop) #endif @@ -292,13 +292,14 @@ inline int BitReader::GetBatch(int num_bits, T* v, int batch_size) { if (UNLIKELY(bit_offset != 0)) { for (; i < batch_size && bit_offset != 0; ++i) { GetValue_(num_bits, &v[i], max_bytes, buffer, &bit_offset, &byte_offset, - &buffered_values); + &buffered_values); } } if (sizeof(T) == 4) { - int num_unpacked = unpack32(reinterpret_cast<const uint32_t*>(buffer + byte_offset), - reinterpret_cast<uint32_t*>(v + i), batch_size - i, num_bits); + int num_unpacked = + unpack32(reinterpret_cast<const uint32_t*>(buffer + byte_offset), + reinterpret_cast<uint32_t*>(v + i), batch_size - i, num_bits); i += num_unpacked; byte_offset += num_unpacked * num_bits / 8; } else { @@ -307,8 +308,10 @@ inline int BitReader::GetBatch(int num_bits, T* v, int batch_size) { while (i < batch_size) { int unpack_size = std::min(buffer_size, batch_size - i); int num_unpacked = unpack32(reinterpret_cast<const uint32_t*>(buffer + byte_offset), - unpack_buffer, unpack_size, num_bits); - if (num_unpacked == 0) { break; } + unpack_buffer, unpack_size, num_bits); + if (num_unpacked == 0) { + break; + } for (int k = 0; k < num_unpacked; ++k) { #ifdef _MSC_VER #pragma warning(push) @@ -332,8 +335,8 @@ inline int BitReader::GetBatch(int num_bits, T* v, int batch_size) { } for (; i < batch_size; ++i) { - GetValue_( - num_bits, &v[i], max_bytes, buffer, &bit_offset, &byte_offset, &buffered_values); + GetValue_(num_bits, &v[i], max_bytes, buffer, &bit_offset, &byte_offset, + &buffered_values); } bit_offset_ = bit_offset; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/bit-util-test.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/bit-util-test.cc b/cpp/src/arrow/util/bit-util-test.cc index cd94558..231bf54 100644 --- a/cpp/src/arrow/util/bit-util-test.cc +++ b/cpp/src/arrow/util/bit-util-test.cc @@ -35,7 +35,9 @@ namespace arrow { static void EnsureCpuInfoInitialized() { - if (!CpuInfo::initialized()) { CpuInfo::Init(); } + if (!CpuInfo::initialized()) { + CpuInfo::Init(); + } } TEST(BitUtilTests, TestIsMultipleOf64) { @@ -68,11 +70,13 @@ TEST(BitUtilTests, TestNextPower2) { ASSERT_EQ(1LL << 62, NextPower2((1LL << 62) - 1)); } -static inline int64_t SlowCountBits( - const uint8_t* data, int64_t bit_offset, int64_t length) { +static inline int64_t SlowCountBits(const uint8_t* data, int64_t bit_offset, + int64_t length) { int64_t count = 0; for (int64_t i = bit_offset; i < bit_offset + length; ++i) { - if (BitUtil::GetBit(data, i)) { ++count; } + if (BitUtil::GetBit(data, i)) { + ++count; + } } return count; } @@ -175,9 +179,9 @@ TEST(BitUtil, TrailingBits) { EXPECT_EQ(BitUtil::TrailingBits(BOOST_BINARY(1 1 1 1 1 1 1 1), 0), 0); EXPECT_EQ(BitUtil::TrailingBits(BOOST_BINARY(1 1 1 1 1 1 1 1), 1), 1); EXPECT_EQ(BitUtil::TrailingBits(BOOST_BINARY(1 1 1 1 1 1 1 1), 64), - BOOST_BINARY(1 1 1 1 1 1 1 1)); + BOOST_BINARY(1 1 1 1 1 1 1 1)); EXPECT_EQ(BitUtil::TrailingBits(BOOST_BINARY(1 1 1 1 1 1 1 1), 100), - BOOST_BINARY(1 1 1 1 1 1 1 1)); + BOOST_BINARY(1 1 1 1 1 1 1 1)); EXPECT_EQ(BitUtil::TrailingBits(0, 1), 0); EXPECT_EQ(BitUtil::TrailingBits(0, 64), 0); EXPECT_EQ(BitUtil::TrailingBits(1LL << 63, 0), 0); @@ -193,12 +197,12 @@ TEST(BitUtil, ByteSwap) { EXPECT_EQ(BitUtil::ByteSwap(static_cast<int32_t>(0x11223344)), 0x44332211); EXPECT_EQ(BitUtil::ByteSwap(static_cast<uint64_t>(0)), 0); - EXPECT_EQ( - BitUtil::ByteSwap(static_cast<uint64_t>(0x1122334455667788)), 0x8877665544332211); + EXPECT_EQ(BitUtil::ByteSwap(static_cast<uint64_t>(0x1122334455667788)), + 0x8877665544332211); EXPECT_EQ(BitUtil::ByteSwap(static_cast<int64_t>(0)), 0); - EXPECT_EQ( - BitUtil::ByteSwap(static_cast<int64_t>(0x1122334455667788)), 0x8877665544332211); + EXPECT_EQ(BitUtil::ByteSwap(static_cast<int64_t>(0x1122334455667788)), + 0x8877665544332211); EXPECT_EQ(BitUtil::ByteSwap(static_cast<int16_t>(0)), 0); EXPECT_EQ(BitUtil::ByteSwap(static_cast<int16_t>(0x1122)), 0x2211); http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/bit-util.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/bit-util.cc b/cpp/src/arrow/util/bit-util.cc index 5bbec6f..f255f95 100644 --- a/cpp/src/arrow/util/bit-util.cc +++ b/cpp/src/arrow/util/bit-util.cc @@ -36,12 +36,14 @@ namespace arrow { void BitUtil::FillBitsFromBytes(const std::vector<uint8_t>& bytes, uint8_t* bits) { for (size_t i = 0; i < bytes.size(); ++i) { - if (bytes[i] > 0) { SetBit(bits, i); } + if (bytes[i] > 0) { + SetBit(bits, i); + } } } -Status BitUtil::BytesToBits( - const std::vector<uint8_t>& bytes, std::shared_ptr<Buffer>* out) { +Status BitUtil::BytesToBits(const std::vector<uint8_t>& bytes, + std::shared_ptr<Buffer>* out) { int64_t bit_length = BitUtil::BytesForBits(bytes.size()); std::shared_ptr<MutableBuffer> buffer; @@ -65,7 +67,9 @@ int64_t CountSetBits(const uint8_t* data, int64_t bit_offset, int64_t length) { // The number of bits until fast_count_start const int64_t initial_bits = std::min(length, fast_count_start - bit_offset); for (int64_t i = bit_offset; i < bit_offset + initial_bits; ++i) { - if (BitUtil::GetBit(data, i)) { ++count; } + if (BitUtil::GetBit(data, i)) { + ++count; + } } const int64_t fast_counts = (length - initial_bits) / pop_len; @@ -85,21 +89,23 @@ int64_t CountSetBits(const uint8_t* data, int64_t bit_offset, int64_t length) { // versions of popcount but the code complexity is likely not worth it) const int64_t tail_index = bit_offset + initial_bits + fast_counts * pop_len; for (int64_t i = tail_index; i < bit_offset + length; ++i) { - if (BitUtil::GetBit(data, i)) { ++count; } + if (BitUtil::GetBit(data, i)) { + ++count; + } } return count; } -Status GetEmptyBitmap( - MemoryPool* pool, int64_t length, std::shared_ptr<MutableBuffer>* result) { +Status GetEmptyBitmap(MemoryPool* pool, int64_t length, + std::shared_ptr<MutableBuffer>* result) { RETURN_NOT_OK(AllocateBuffer(pool, BitUtil::BytesForBits(length), result)); memset((*result)->mutable_data(), 0, static_cast<size_t>((*result)->size())); return Status::OK(); } Status CopyBitmap(MemoryPool* pool, const uint8_t* data, int64_t offset, int64_t length, - std::shared_ptr<Buffer>* out) { + std::shared_ptr<Buffer>* out) { std::shared_ptr<MutableBuffer> buffer; RETURN_NOT_OK(GetEmptyBitmap(pool, length, &buffer)); uint8_t* dest = buffer->mutable_data(); @@ -111,12 +117,14 @@ Status CopyBitmap(MemoryPool* pool, const uint8_t* data, int64_t offset, int64_t } bool BitmapEquals(const uint8_t* left, int64_t left_offset, const uint8_t* right, - int64_t right_offset, int64_t bit_length) { + int64_t right_offset, int64_t bit_length) { if (left_offset % 8 == 0 && right_offset % 8 == 0) { // byte aligned, can use memcmp bool bytes_equal = std::memcmp(left + left_offset / 8, right + right_offset / 8, - bit_length / 8) == 0; - if (!bytes_equal) { return false; } + bit_length / 8) == 0; + if (!bytes_equal) { + return false; + } for (int64_t i = (bit_length / 8) * 8; i < bit_length; ++i) { if (BitUtil::GetBit(left, left_offset + i) != BitUtil::GetBit(right, right_offset + i)) { http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/bit-util.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/bit-util.h b/cpp/src/arrow/util/bit-util.h index d055c75..f036763 100644 --- a/cpp/src/arrow/util/bit-util.h +++ b/cpp/src/arrow/util/bit-util.h @@ -101,17 +101,11 @@ static constexpr uint8_t kBitmask[] = {1, 2, 4, 8, 16, 32, 64, 128}; // the ~i byte version of kBitmaks static constexpr uint8_t kFlippedBitmask[] = {254, 253, 251, 247, 239, 223, 191, 127}; -static inline int64_t CeilByte(int64_t size) { - return (size + 7) & ~7; -} +static inline int64_t CeilByte(int64_t size) { return (size + 7) & ~7; } -static inline int64_t BytesForBits(int64_t size) { - return CeilByte(size) / 8; -} +static inline int64_t BytesForBits(int64_t size) { return CeilByte(size) / 8; } -static inline int64_t Ceil2Bytes(int64_t size) { - return (size + 15) & ~15; -} +static inline int64_t Ceil2Bytes(int64_t size) { return (size + 15) & ~15; } static inline bool GetBit(const uint8_t* bits, int64_t i) { return (bits[i / 8] & kBitmask[i % 8]) != 0; @@ -125,13 +119,13 @@ static inline void ClearBit(uint8_t* bits, int64_t i) { bits[i / 8] &= kFlippedBitmask[i % 8]; } -static inline void SetBit(uint8_t* bits, int64_t i) { - bits[i / 8] |= kBitmask[i % 8]; -} +static inline void SetBit(uint8_t* bits, int64_t i) { bits[i / 8] |= kBitmask[i % 8]; } /// Set bit if is_set is true, but cannot clear bit static inline void SetArrayBit(uint8_t* bits, int i, bool is_set) { - if (is_set) { SetBit(bits, i); } + if (is_set) { + SetBit(bits, i); + } } static inline void SetBitTo(uint8_t* bits, int64_t i, bool bit_is_set) { @@ -168,13 +162,9 @@ static inline int64_t NextPower2(int64_t n) { return n; } -static inline bool IsMultipleOf64(int64_t n) { - return (n & 63) == 0; -} +static inline bool IsMultipleOf64(int64_t n) { return (n & 63) == 0; } -static inline bool IsMultipleOf8(int64_t n) { - return (n & 7) == 0; -} +static inline bool IsMultipleOf8(int64_t n) { return (n & 7) == 0; } /// Returns the ceil of value/divisor static inline int64_t Ceil(int64_t value, int64_t divisor) { @@ -206,34 +196,22 @@ static inline int RoundDownToPowerOf2(int value, int factor) { /// Specialized round up and down functions for frequently used factors, /// like 8 (bits->bytes), 32 (bits->i32), and 64 (bits->i64). /// Returns the rounded up number of bytes that fit the number of bits. -static inline uint32_t RoundUpNumBytes(uint32_t bits) { - return (bits + 7) >> 3; -} +static inline uint32_t RoundUpNumBytes(uint32_t bits) { return (bits + 7) >> 3; } /// Returns the rounded down number of bytes that fit the number of bits. -static inline uint32_t RoundDownNumBytes(uint32_t bits) { - return bits >> 3; -} +static inline uint32_t RoundDownNumBytes(uint32_t bits) { return bits >> 3; } /// Returns the rounded up to 32 multiple. Used for conversions of bits to i32. -static inline uint32_t RoundUpNumi32(uint32_t bits) { - return (bits + 31) >> 5; -} +static inline uint32_t RoundUpNumi32(uint32_t bits) { return (bits + 31) >> 5; } /// Returns the rounded up 32 multiple. -static inline uint32_t RoundDownNumi32(uint32_t bits) { - return bits >> 5; -} +static inline uint32_t RoundDownNumi32(uint32_t bits) { return bits >> 5; } /// Returns the rounded up to 64 multiple. Used for conversions of bits to i64. -static inline uint32_t RoundUpNumi64(uint32_t bits) { - return (bits + 63) >> 6; -} +static inline uint32_t RoundUpNumi64(uint32_t bits) { return (bits + 63) >> 6; } /// Returns the rounded down to 64 multiple. -static inline uint32_t RoundDownNumi64(uint32_t bits) { - return bits >> 6; -} +static inline uint32_t RoundDownNumi64(uint32_t bits) { return bits >> 6; } static inline int64_t RoundUpToMultipleOf64(int64_t num) { // TODO(wesm): is this definitely needed? @@ -242,7 +220,9 @@ static inline int64_t RoundUpToMultipleOf64(int64_t num) { constexpr int64_t force_carry_addend = round_to - 1; constexpr int64_t truncate_bitmask = ~(round_to - 1); constexpr int64_t max_roundable_num = std::numeric_limits<int64_t>::max() - round_to; - if (num <= max_roundable_num) { return (num + force_carry_addend) & truncate_bitmask; } + if (num <= max_roundable_num) { + return (num + force_carry_addend) & truncate_bitmask; + } // handle overflow case. This should result in a malloc error upstream return num; } @@ -252,8 +232,7 @@ static inline int64_t RoundUpToMultipleOf64(int64_t num) { /// might be a much faster way to implement this. static inline int PopcountNoHw(uint64_t x) { int count = 0; - for (; x != 0; ++count) - x &= x - 1; + for (; x != 0; ++count) x &= x - 1; return count; } @@ -297,21 +276,16 @@ static inline int Log2(uint64_t x) { // (floor(log2(n)) = MSB(n) (0-indexed)) --x; int result = 1; - while (x >>= 1) - ++result; + while (x >>= 1) ++result; return result; } /// Swaps the byte order (i.e. endianess) -static inline int64_t ByteSwap(int64_t value) { - return ARROW_BYTE_SWAP64(value); -} +static inline int64_t ByteSwap(int64_t value) { return ARROW_BYTE_SWAP64(value); } static inline uint64_t ByteSwap(uint64_t value) { return static_cast<uint64_t>(ARROW_BYTE_SWAP64(value)); } -static inline int32_t ByteSwap(int32_t value) { - return ARROW_BYTE_SWAP32(value); -} +static inline int32_t ByteSwap(int32_t value) { return ARROW_BYTE_SWAP32(value); } static inline uint32_t ByteSwap(uint32_t value) { return static_cast<uint32_t>(ARROW_BYTE_SWAP32(value)); } @@ -352,84 +326,36 @@ static inline void ByteSwap(void* dst, const void* src, int len) { /// Converts to big endian format (if not already in big endian) from the /// machine's native endian format. #if __BYTE_ORDER == __LITTLE_ENDIAN -static inline int64_t ToBigEndian(int64_t value) { - return ByteSwap(value); -} -static inline uint64_t ToBigEndian(uint64_t value) { - return ByteSwap(value); -} -static inline int32_t ToBigEndian(int32_t value) { - return ByteSwap(value); -} -static inline uint32_t ToBigEndian(uint32_t value) { - return ByteSwap(value); -} -static inline int16_t ToBigEndian(int16_t value) { - return ByteSwap(value); -} -static inline uint16_t ToBigEndian(uint16_t value) { - return ByteSwap(value); -} +static inline int64_t ToBigEndian(int64_t value) { return ByteSwap(value); } +static inline uint64_t ToBigEndian(uint64_t value) { return ByteSwap(value); } +static inline int32_t ToBigEndian(int32_t value) { return ByteSwap(value); } +static inline uint32_t ToBigEndian(uint32_t value) { return ByteSwap(value); } +static inline int16_t ToBigEndian(int16_t value) { return ByteSwap(value); } +static inline uint16_t ToBigEndian(uint16_t value) { return ByteSwap(value); } #else -static inline int64_t ToBigEndian(int64_t val) { - return val; -} -static inline uint64_t ToBigEndian(uint64_t val) { - return val; -} -static inline int32_t ToBigEndian(int32_t val) { - return val; -} -static inline uint32_t ToBigEndian(uint32_t val) { - return val; -} -static inline int16_t ToBigEndian(int16_t val) { - return val; -} -static inline uint16_t ToBigEndian(uint16_t val) { - return val; -} +static inline int64_t ToBigEndian(int64_t val) { return val; } +static inline uint64_t ToBigEndian(uint64_t val) { return val; } +static inline int32_t ToBigEndian(int32_t val) { return val; } +static inline uint32_t ToBigEndian(uint32_t val) { return val; } +static inline int16_t ToBigEndian(int16_t val) { return val; } +static inline uint16_t ToBigEndian(uint16_t val) { return val; } #endif /// Converts from big endian format to the machine's native endian format. #if __BYTE_ORDER == __LITTLE_ENDIAN -static inline int64_t FromBigEndian(int64_t value) { - return ByteSwap(value); -} -static inline uint64_t FromBigEndian(uint64_t value) { - return ByteSwap(value); -} -static inline int32_t FromBigEndian(int32_t value) { - return ByteSwap(value); -} -static inline uint32_t FromBigEndian(uint32_t value) { - return ByteSwap(value); -} -static inline int16_t FromBigEndian(int16_t value) { - return ByteSwap(value); -} -static inline uint16_t FromBigEndian(uint16_t value) { - return ByteSwap(value); -} +static inline int64_t FromBigEndian(int64_t value) { return ByteSwap(value); } +static inline uint64_t FromBigEndian(uint64_t value) { return ByteSwap(value); } +static inline int32_t FromBigEndian(int32_t value) { return ByteSwap(value); } +static inline uint32_t FromBigEndian(uint32_t value) { return ByteSwap(value); } +static inline int16_t FromBigEndian(int16_t value) { return ByteSwap(value); } +static inline uint16_t FromBigEndian(uint16_t value) { return ByteSwap(value); } #else -static inline int64_t FromBigEndian(int64_t val) { - return val; -} -static inline uint64_t FromBigEndian(uint64_t val) { - return val; -} -static inline int32_t FromBigEndian(int32_t val) { - return val; -} -static inline uint32_t FromBigEndian(uint32_t val) { - return val; -} -static inline int16_t FromBigEndian(int16_t val) { - return val; -} -static inline uint16_t FromBigEndian(uint16_t val) { - return val; -} +static inline int64_t FromBigEndian(int64_t val) { return val; } +static inline uint64_t FromBigEndian(uint64_t val) { return val; } +static inline int32_t FromBigEndian(int32_t val) { return val; } +static inline uint32_t FromBigEndian(uint32_t val) { return val; } +static inline int16_t FromBigEndian(int16_t val) { return val; } +static inline uint16_t FromBigEndian(uint16_t val) { return val; } #endif // Logical right shift for signed integer types @@ -449,8 +375,8 @@ ARROW_EXPORT Status BytesToBits(const std::vector<uint8_t>&, std::shared_ptr<Buf // ---------------------------------------------------------------------- // Bitmap utilities -Status ARROW_EXPORT GetEmptyBitmap( - MemoryPool* pool, int64_t length, std::shared_ptr<MutableBuffer>* result); +Status ARROW_EXPORT GetEmptyBitmap(MemoryPool* pool, int64_t length, + std::shared_ptr<MutableBuffer>* result); /// Copy a bit range of an existing bitmap /// @@ -462,7 +388,7 @@ Status ARROW_EXPORT GetEmptyBitmap( /// /// \return Status message Status ARROW_EXPORT CopyBitmap(MemoryPool* pool, const uint8_t* bitmap, int64_t offset, - int64_t length, std::shared_ptr<Buffer>* out); + int64_t length, std::shared_ptr<Buffer>* out); /// Compute the number of 1's in the given data array /// @@ -471,11 +397,12 @@ Status ARROW_EXPORT CopyBitmap(MemoryPool* pool, const uint8_t* bitmap, int64_t /// \param[in] length the number of bits to inspect in the bitmap relative to the offset /// /// \return The number of set (1) bits in the range -int64_t ARROW_EXPORT CountSetBits( - const uint8_t* data, int64_t bit_offset, int64_t length); +int64_t ARROW_EXPORT CountSetBits(const uint8_t* data, int64_t bit_offset, + int64_t length); bool ARROW_EXPORT BitmapEquals(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t bit_length); + const uint8_t* right, int64_t right_offset, + int64_t bit_length); } // namespace arrow #endif // ARROW_UTIL_BIT_UTIL_H http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/bpacking.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/bpacking.h b/cpp/src/arrow/util/bpacking.h index fce5f55..4d25de0 100644 --- a/cpp/src/arrow/util/bpacking.h +++ b/cpp/src/arrow/util/bpacking.h @@ -3199,136 +3199,103 @@ inline int unpack32(const uint32_t* in, uint32_t* out, int batch_size, int num_b switch (num_bits) { case 0: - for (int i = 0; i < num_loops; ++i) - in = nullunpacker32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = nullunpacker32(in, out + i * 32); break; case 1: - for (int i = 0; i < num_loops; ++i) - in = unpack1_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack1_32(in, out + i * 32); break; case 2: - for (int i = 0; i < num_loops; ++i) - in = unpack2_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack2_32(in, out + i * 32); break; case 3: - for (int i = 0; i < num_loops; ++i) - in = unpack3_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack3_32(in, out + i * 32); break; case 4: - for (int i = 0; i < num_loops; ++i) - in = unpack4_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack4_32(in, out + i * 32); break; case 5: - for (int i = 0; i < num_loops; ++i) - in = unpack5_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack5_32(in, out + i * 32); break; case 6: - for (int i = 0; i < num_loops; ++i) - in = unpack6_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack6_32(in, out + i * 32); break; case 7: - for (int i = 0; i < num_loops; ++i) - in = unpack7_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack7_32(in, out + i * 32); break; case 8: - for (int i = 0; i < num_loops; ++i) - in = unpack8_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack8_32(in, out + i * 32); break; case 9: - for (int i = 0; i < num_loops; ++i) - in = unpack9_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack9_32(in, out + i * 32); break; case 10: - for (int i = 0; i < num_loops; ++i) - in = unpack10_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack10_32(in, out + i * 32); break; case 11: - for (int i = 0; i < num_loops; ++i) - in = unpack11_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack11_32(in, out + i * 32); break; case 12: - for (int i = 0; i < num_loops; ++i) - in = unpack12_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack12_32(in, out + i * 32); break; case 13: - for (int i = 0; i < num_loops; ++i) - in = unpack13_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack13_32(in, out + i * 32); break; case 14: - for (int i = 0; i < num_loops; ++i) - in = unpack14_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack14_32(in, out + i * 32); break; case 15: - for (int i = 0; i < num_loops; ++i) - in = unpack15_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack15_32(in, out + i * 32); break; case 16: - for (int i = 0; i < num_loops; ++i) - in = unpack16_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack16_32(in, out + i * 32); break; case 17: - for (int i = 0; i < num_loops; ++i) - in = unpack17_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack17_32(in, out + i * 32); break; case 18: - for (int i = 0; i < num_loops; ++i) - in = unpack18_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack18_32(in, out + i * 32); break; case 19: - for (int i = 0; i < num_loops; ++i) - in = unpack19_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack19_32(in, out + i * 32); break; case 20: - for (int i = 0; i < num_loops; ++i) - in = unpack20_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack20_32(in, out + i * 32); break; case 21: - for (int i = 0; i < num_loops; ++i) - in = unpack21_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack21_32(in, out + i * 32); break; case 22: - for (int i = 0; i < num_loops; ++i) - in = unpack22_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack22_32(in, out + i * 32); break; case 23: - for (int i = 0; i < num_loops; ++i) - in = unpack23_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack23_32(in, out + i * 32); break; case 24: - for (int i = 0; i < num_loops; ++i) - in = unpack24_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack24_32(in, out + i * 32); break; case 25: - for (int i = 0; i < num_loops; ++i) - in = unpack25_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack25_32(in, out + i * 32); break; case 26: - for (int i = 0; i < num_loops; ++i) - in = unpack26_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack26_32(in, out + i * 32); break; case 27: - for (int i = 0; i < num_loops; ++i) - in = unpack27_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack27_32(in, out + i * 32); break; case 28: - for (int i = 0; i < num_loops; ++i) - in = unpack28_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack28_32(in, out + i * 32); break; case 29: - for (int i = 0; i < num_loops; ++i) - in = unpack29_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack29_32(in, out + i * 32); break; case 30: - for (int i = 0; i < num_loops; ++i) - in = unpack30_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack30_32(in, out + i * 32); break; case 31: - for (int i = 0; i < num_loops; ++i) - in = unpack31_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack31_32(in, out + i * 32); break; case 32: - for (int i = 0; i < num_loops; ++i) - in = unpack32_32(in, out + i * 32); + for (int i = 0; i < num_loops; ++i) in = unpack32_32(in, out + i * 32); break; default: DCHECK(false) << "Unsupported num_bits"; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression-test.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression-test.cc b/cpp/src/arrow/util/compression-test.cc index f7739fc..64896dd 100644 --- a/cpp/src/arrow/util/compression-test.cc +++ b/cpp/src/arrow/util/compression-test.cc @@ -15,8 +15,8 @@ // specific language governing permissions and limitations // under the License. -#include <cstdint> #include <gtest/gtest.h> +#include <cstdint> #include <string> #include <vector> @@ -43,25 +43,25 @@ void CheckCodecRoundtrip(const vector<uint8_t>& data) { // compress with c1 int64_t actual_size; - ASSERT_OK(c1->Compress( - data.size(), &data[0], max_compressed_len, &compressed[0], &actual_size)); + ASSERT_OK(c1->Compress(data.size(), &data[0], max_compressed_len, &compressed[0], + &actual_size)); compressed.resize(actual_size); // decompress with c2 - ASSERT_OK(c2->Decompress( - compressed.size(), &compressed[0], decompressed.size(), &decompressed[0])); + ASSERT_OK(c2->Decompress(compressed.size(), &compressed[0], decompressed.size(), + &decompressed[0])); ASSERT_EQ(data, decompressed); // compress with c2 int64_t actual_size2; - ASSERT_OK(c2->Compress( - data.size(), &data[0], max_compressed_len, &compressed[0], &actual_size2)); + ASSERT_OK(c2->Compress(data.size(), &data[0], max_compressed_len, &compressed[0], + &actual_size2)); ASSERT_EQ(actual_size2, actual_size); // decompress with c1 - ASSERT_OK(c1->Decompress( - compressed.size(), &compressed[0], decompressed.size(), &decompressed[0])); + ASSERT_OK(c1->Decompress(compressed.size(), &compressed[0], decompressed.size(), + &decompressed[0])); ASSERT_EQ(data, decompressed); } @@ -76,24 +76,14 @@ void CheckCodec() { } } -TEST(TestCompressors, Snappy) { - CheckCodec<Compression::SNAPPY>(); -} +TEST(TestCompressors, Snappy) { CheckCodec<Compression::SNAPPY>(); } -TEST(TestCompressors, Brotli) { - CheckCodec<Compression::BROTLI>(); -} +TEST(TestCompressors, Brotli) { CheckCodec<Compression::BROTLI>(); } -TEST(TestCompressors, GZip) { - CheckCodec<Compression::GZIP>(); -} +TEST(TestCompressors, GZip) { CheckCodec<Compression::GZIP>(); } -TEST(TestCompressors, ZSTD) { - CheckCodec<Compression::ZSTD>(); -} +TEST(TestCompressors, ZSTD) { CheckCodec<Compression::ZSTD>(); } -TEST(TestCompressors, Lz4) { - CheckCodec<Compression::LZ4>(); -} +TEST(TestCompressors, Lz4) { CheckCodec<Compression::LZ4>(); } } // namespace arrow http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression.h b/cpp/src/arrow/util/compression.h index 19c6117..ae187a7 100644 --- a/cpp/src/arrow/util/compression.h +++ b/cpp/src/arrow/util/compression.h @@ -37,10 +37,11 @@ class ARROW_EXPORT Codec { static Status Create(Compression::type codec, std::unique_ptr<Codec>* out); virtual Status Decompress(int64_t input_len, const uint8_t* input, int64_t output_len, - uint8_t* output_buffer) = 0; + uint8_t* output_buffer) = 0; virtual Status Compress(int64_t input_len, const uint8_t* input, - int64_t output_buffer_len, uint8_t* output_buffer, int64_t* output_length) = 0; + int64_t output_buffer_len, uint8_t* output_buffer, + int64_t* output_length) = 0; virtual int64_t MaxCompressedLen(int64_t input_len, const uint8_t* input) = 0; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression_brotli.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression_brotli.cc b/cpp/src/arrow/util/compression_brotli.cc index c03573b..e463908 100644 --- a/cpp/src/arrow/util/compression_brotli.cc +++ b/cpp/src/arrow/util/compression_brotli.cc @@ -33,8 +33,8 @@ namespace arrow { // ---------------------------------------------------------------------- // Brotli implementation -Status BrotliCodec::Decompress( - int64_t input_len, const uint8_t* input, int64_t output_len, uint8_t* output_buffer) { +Status BrotliCodec::Decompress(int64_t input_len, const uint8_t* input, + int64_t output_len, uint8_t* output_buffer) { size_t output_size = output_len; if (BrotliDecoderDecompress(input_len, input, &output_size, output_buffer) != BROTLI_DECODER_RESULT_SUCCESS) { @@ -48,12 +48,13 @@ int64_t BrotliCodec::MaxCompressedLen(int64_t input_len, const uint8_t* input) { } Status BrotliCodec::Compress(int64_t input_len, const uint8_t* input, - int64_t output_buffer_len, uint8_t* output_buffer, int64_t* output_length) { + int64_t output_buffer_len, uint8_t* output_buffer, + int64_t* output_length) { size_t output_len = output_buffer_len; // TODO: Make quality configurable. We use 8 as a default as it is the best // trade-off for Parquet workload if (BrotliEncoderCompress(8, BROTLI_DEFAULT_WINDOW, BROTLI_DEFAULT_MODE, input_len, - input, &output_len, output_buffer) == BROTLI_FALSE) { + input, &output_len, output_buffer) == BROTLI_FALSE) { return Status::IOError("Brotli compression failure."); } *output_length = output_len; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression_brotli.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression_brotli.h b/cpp/src/arrow/util/compression_brotli.h index 08bd337..9e92cb1 100644 --- a/cpp/src/arrow/util/compression_brotli.h +++ b/cpp/src/arrow/util/compression_brotli.h @@ -30,10 +30,10 @@ namespace arrow { class ARROW_EXPORT BrotliCodec : public Codec { public: Status Decompress(int64_t input_len, const uint8_t* input, int64_t output_len, - uint8_t* output_buffer) override; + uint8_t* output_buffer) override; Status Compress(int64_t input_len, const uint8_t* input, int64_t output_buffer_len, - uint8_t* output_buffer, int64_t* output_length) override; + uint8_t* output_buffer, int64_t* output_length) override; int64_t MaxCompressedLen(int64_t input_len, const uint8_t* input) override; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression_lz4.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression_lz4.cc b/cpp/src/arrow/util/compression_lz4.cc index 65eaa08..295e9a4 100644 --- a/cpp/src/arrow/util/compression_lz4.cc +++ b/cpp/src/arrow/util/compression_lz4.cc @@ -32,12 +32,14 @@ namespace arrow { // ---------------------------------------------------------------------- // Lz4 implementation -Status Lz4Codec::Decompress( - int64_t input_len, const uint8_t* input, int64_t output_len, uint8_t* output_buffer) { - int64_t decompressed_size = LZ4_decompress_safe(reinterpret_cast<const char*>(input), - reinterpret_cast<char*>(output_buffer), static_cast<int>(input_len), - static_cast<int>(output_len)); - if (decompressed_size < 1) { return Status::IOError("Corrupt Lz4 compressed data."); } +Status Lz4Codec::Decompress(int64_t input_len, const uint8_t* input, int64_t output_len, + uint8_t* output_buffer) { + int64_t decompressed_size = LZ4_decompress_safe( + reinterpret_cast<const char*>(input), reinterpret_cast<char*>(output_buffer), + static_cast<int>(input_len), static_cast<int>(output_len)); + if (decompressed_size < 1) { + return Status::IOError("Corrupt Lz4 compressed data."); + } return Status::OK(); } @@ -46,11 +48,14 @@ int64_t Lz4Codec::MaxCompressedLen(int64_t input_len, const uint8_t* input) { } Status Lz4Codec::Compress(int64_t input_len, const uint8_t* input, - int64_t output_buffer_len, uint8_t* output_buffer, int64_t* output_length) { - *output_length = LZ4_compress_default(reinterpret_cast<const char*>(input), - reinterpret_cast<char*>(output_buffer), static_cast<int>(input_len), - static_cast<int>(output_buffer_len)); - if (*output_length < 1) { return Status::IOError("Lz4 compression failure."); } + int64_t output_buffer_len, uint8_t* output_buffer, + int64_t* output_length) { + *output_length = LZ4_compress_default( + reinterpret_cast<const char*>(input), reinterpret_cast<char*>(output_buffer), + static_cast<int>(input_len), static_cast<int>(output_buffer_len)); + if (*output_length < 1) { + return Status::IOError("Lz4 compression failure."); + } return Status::OK(); } http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression_lz4.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression_lz4.h b/cpp/src/arrow/util/compression_lz4.h index 9668fec..0af2289 100644 --- a/cpp/src/arrow/util/compression_lz4.h +++ b/cpp/src/arrow/util/compression_lz4.h @@ -30,10 +30,10 @@ namespace arrow { class ARROW_EXPORT Lz4Codec : public Codec { public: Status Decompress(int64_t input_len, const uint8_t* input, int64_t output_len, - uint8_t* output_buffer) override; + uint8_t* output_buffer) override; Status Compress(int64_t input_len, const uint8_t* input, int64_t output_buffer_len, - uint8_t* output_buffer, int64_t* output_length) override; + uint8_t* output_buffer, int64_t* output_length) override; int64_t MaxCompressedLen(int64_t input_len, const uint8_t* input) override; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression_snappy.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression_snappy.cc b/cpp/src/arrow/util/compression_snappy.cc index db2b673..947ffe5 100644 --- a/cpp/src/arrow/util/compression_snappy.cc +++ b/cpp/src/arrow/util/compression_snappy.cc @@ -37,10 +37,11 @@ namespace arrow { // ---------------------------------------------------------------------- // Snappy implementation -Status SnappyCodec::Decompress( - int64_t input_len, const uint8_t* input, int64_t output_len, uint8_t* output_buffer) { +Status SnappyCodec::Decompress(int64_t input_len, const uint8_t* input, + int64_t output_len, uint8_t* output_buffer) { if (!snappy::RawUncompress(reinterpret_cast<const char*>(input), - static_cast<size_t>(input_len), reinterpret_cast<char*>(output_buffer))) { + static_cast<size_t>(input_len), + reinterpret_cast<char*>(output_buffer))) { return Status::IOError("Corrupt snappy compressed data."); } return Status::OK(); @@ -51,11 +52,12 @@ int64_t SnappyCodec::MaxCompressedLen(int64_t input_len, const uint8_t* input) { } Status SnappyCodec::Compress(int64_t input_len, const uint8_t* input, - int64_t output_buffer_len, uint8_t* output_buffer, int64_t* output_length) { + int64_t output_buffer_len, uint8_t* output_buffer, + int64_t* output_length) { size_t output_len; snappy::RawCompress(reinterpret_cast<const char*>(input), - static_cast<size_t>(input_len), reinterpret_cast<char*>(output_buffer), - &output_len); + static_cast<size_t>(input_len), + reinterpret_cast<char*>(output_buffer), &output_len); *output_length = static_cast<int64_t>(output_len); return Status::OK(); } http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression_snappy.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression_snappy.h b/cpp/src/arrow/util/compression_snappy.h index 25281e1..5cc10c4 100644 --- a/cpp/src/arrow/util/compression_snappy.h +++ b/cpp/src/arrow/util/compression_snappy.h @@ -29,10 +29,10 @@ namespace arrow { class ARROW_EXPORT SnappyCodec : public Codec { public: Status Decompress(int64_t input_len, const uint8_t* input, int64_t output_len, - uint8_t* output_buffer) override; + uint8_t* output_buffer) override; Status Compress(int64_t input_len, const uint8_t* input, int64_t output_buffer_len, - uint8_t* output_buffer, int64_t* output_length) override; + uint8_t* output_buffer, int64_t* output_length) override; int64_t MaxCompressedLen(int64_t input_len, const uint8_t* input) override; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression_zlib.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression_zlib.cc b/cpp/src/arrow/util/compression_zlib.cc index 3ff33b8..ae6627e 100644 --- a/cpp/src/arrow/util/compression_zlib.cc +++ b/cpp/src/arrow/util/compression_zlib.cc @@ -69,7 +69,7 @@ class GZipCodec::GZipCodecImpl { window_bits += GZIP_CODEC; } if ((ret = deflateInit2(&stream_, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits, 9, - Z_DEFAULT_STRATEGY)) != Z_OK) { + Z_DEFAULT_STRATEGY)) != Z_OK) { std::stringstream ss; ss << "zlib deflateInit failed: " << std::string(stream_.msg); return Status::IOError(ss.str()); @@ -79,7 +79,9 @@ class GZipCodec::GZipCodecImpl { } void EndCompressor() { - if (compressor_initialized_) { (void)deflateEnd(&stream_); } + if (compressor_initialized_) { + (void)deflateEnd(&stream_); + } compressor_initialized_ = false; } @@ -100,13 +102,17 @@ class GZipCodec::GZipCodecImpl { } void EndDecompressor() { - if (decompressor_initialized_) { (void)inflateEnd(&stream_); } + if (decompressor_initialized_) { + (void)inflateEnd(&stream_); + } decompressor_initialized_ = false; } Status Decompress(int64_t input_length, const uint8_t* input, int64_t output_length, - uint8_t* output) { - if (!decompressor_initialized_) { RETURN_NOT_OK(InitDecompressor()); } + uint8_t* output) { + if (!decompressor_initialized_) { + RETURN_NOT_OK(InitDecompressor()); + } if (output_length == 0) { // The zlib library does not allow *output to be NULL, even when output_length // is 0 (inflate() will return Z_STREAM_ERROR). We don't consider this an @@ -168,8 +174,10 @@ class GZipCodec::GZipCodecImpl { } Status Compress(int64_t input_length, const uint8_t* input, int64_t output_buffer_len, - uint8_t* output, int64_t* output_length) { - if (!compressor_initialized_) { RETURN_NOT_OK(InitCompressor()); } + uint8_t* output, int64_t* output_length) { + if (!compressor_initialized_) { + RETURN_NOT_OK(InitCompressor()); + } stream_.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(input)); stream_.avail_in = static_cast<uInt>(input_length); stream_.next_out = reinterpret_cast<Bytef*>(output); @@ -218,14 +226,12 @@ class GZipCodec::GZipCodecImpl { bool decompressor_initialized_; }; -GZipCodec::GZipCodec(Format format) { - impl_.reset(new GZipCodecImpl(format)); -} +GZipCodec::GZipCodec(Format format) { impl_.reset(new GZipCodecImpl(format)); } GZipCodec::~GZipCodec() {} Status GZipCodec::Decompress(int64_t input_length, const uint8_t* input, - int64_t output_buffer_len, uint8_t* output) { + int64_t output_buffer_len, uint8_t* output) { return impl_->Decompress(input_length, input, output_buffer_len, output); } @@ -234,12 +240,11 @@ int64_t GZipCodec::MaxCompressedLen(int64_t input_length, const uint8_t* input) } Status GZipCodec::Compress(int64_t input_length, const uint8_t* input, - int64_t output_buffer_len, uint8_t* output, int64_t* output_length) { + int64_t output_buffer_len, uint8_t* output, + int64_t* output_length) { return impl_->Compress(input_length, input, output_buffer_len, output, output_length); } -const char* GZipCodec::name() const { - return "gzip"; -} +const char* GZipCodec::name() const { return "gzip"; } } // namespace arrow http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression_zlib.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression_zlib.h b/cpp/src/arrow/util/compression_zlib.h index 517a061..f55d668 100644 --- a/cpp/src/arrow/util/compression_zlib.h +++ b/cpp/src/arrow/util/compression_zlib.h @@ -40,10 +40,10 @@ class ARROW_EXPORT GZipCodec : public Codec { virtual ~GZipCodec(); Status Decompress(int64_t input_len, const uint8_t* input, int64_t output_len, - uint8_t* output_buffer) override; + uint8_t* output_buffer) override; Status Compress(int64_t input_len, const uint8_t* input, int64_t output_buffer_len, - uint8_t* output_buffer, int64_t* output_length) override; + uint8_t* output_buffer, int64_t* output_length) override; int64_t MaxCompressedLen(int64_t input_len, const uint8_t* input) override; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression_zstd.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression_zstd.cc b/cpp/src/arrow/util/compression_zstd.cc index 5511cb9..ac6e906 100644 --- a/cpp/src/arrow/util/compression_zstd.cc +++ b/cpp/src/arrow/util/compression_zstd.cc @@ -32,10 +32,11 @@ namespace arrow { // ---------------------------------------------------------------------- // ZSTD implementation -Status ZSTDCodec::Decompress( - int64_t input_len, const uint8_t* input, int64_t output_len, uint8_t* output_buffer) { - int64_t decompressed_size = ZSTD_decompress(output_buffer, - static_cast<size_t>(output_len), input, static_cast<size_t>(input_len)); +Status ZSTDCodec::Decompress(int64_t input_len, const uint8_t* input, int64_t output_len, + uint8_t* output_buffer) { + int64_t decompressed_size = + ZSTD_decompress(output_buffer, static_cast<size_t>(output_len), input, + static_cast<size_t>(input_len)); if (decompressed_size != output_len) { return Status::IOError("Corrupt ZSTD compressed data."); } @@ -47,9 +48,10 @@ int64_t ZSTDCodec::MaxCompressedLen(int64_t input_len, const uint8_t* input) { } Status ZSTDCodec::Compress(int64_t input_len, const uint8_t* input, - int64_t output_buffer_len, uint8_t* output_buffer, int64_t* output_length) { + int64_t output_buffer_len, uint8_t* output_buffer, + int64_t* output_length) { *output_length = ZSTD_compress(output_buffer, static_cast<size_t>(output_buffer_len), - input, static_cast<size_t>(input_len), 1); + input, static_cast<size_t>(input_len), 1); if (ZSTD_isError(*output_length)) { return Status::IOError("ZSTD compression failure."); } http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/compression_zstd.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/compression_zstd.h b/cpp/src/arrow/util/compression_zstd.h index 2356d58..6e40e19 100644 --- a/cpp/src/arrow/util/compression_zstd.h +++ b/cpp/src/arrow/util/compression_zstd.h @@ -30,10 +30,10 @@ namespace arrow { class ARROW_EXPORT ZSTDCodec : public Codec { public: Status Decompress(int64_t input_len, const uint8_t* input, int64_t output_len, - uint8_t* output_buffer) override; + uint8_t* output_buffer) override; Status Compress(int64_t input_len, const uint8_t* input, int64_t output_buffer_len, - uint8_t* output_buffer, int64_t* output_length) override; + uint8_t* output_buffer, int64_t* output_length) override; int64_t MaxCompressedLen(int64_t input_len, const uint8_t* input) override; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/cpu-info.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/cpu-info.cc b/cpp/src/arrow/util/cpu-info.cc index dcd6b40..b0667cb 100644 --- a/cpp/src/arrow/util/cpu-info.cc +++ b/cpp/src/arrow/util/cpu-info.cc @@ -66,7 +66,9 @@ static struct { string name; int64_t flag; } flag_mappings[] = { - {"ssse3", CpuInfo::SSSE3}, {"sse4_1", CpuInfo::SSE4_1}, {"sse4_2", CpuInfo::SSE4_2}, + {"ssse3", CpuInfo::SSSE3}, + {"sse4_1", CpuInfo::SSE4_1}, + {"sse4_2", CpuInfo::SSE4_2}, {"popcnt", CpuInfo::POPCNT}, }; static const int64_t num_flags = sizeof(flag_mappings) / sizeof(flag_mappings[0]); @@ -78,14 +80,18 @@ static const int64_t num_flags = sizeof(flag_mappings) / sizeof(flag_mappings[0] int64_t ParseCPUFlags(const string& values) { int64_t flags = 0; for (int i = 0; i < num_flags; ++i) { - if (contains(values, flag_mappings[i].name)) { flags |= flag_mappings[i].flag; } + if (contains(values, flag_mappings[i].name)) { + flags |= flag_mappings[i].flag; + } } return flags; } #ifdef _WIN32 bool RetrieveCacheSize(int64_t* cache_sizes) { - if (!cache_sizes) { return false; } + if (!cache_sizes) { + return false; + } PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = nullptr; PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer_position = nullptr; DWORD buffer_size = 0; @@ -95,7 +101,9 @@ bool RetrieveCacheSize(int64_t* cache_sizes) { (GetLogicalProcessorInformationFuncPointer)GetProcAddress( GetModuleHandle("kernel32"), "GetLogicalProcessorInformation"); - if (!func_pointer) { return false; } + if (!func_pointer) { + return false; + } // Get buffer size if (func_pointer(buffer, &buffer_size) && GetLastError() != ERROR_INSUFFICIENT_BUFFER) @@ -103,7 +111,9 @@ bool RetrieveCacheSize(int64_t* cache_sizes) { buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(buffer_size); - if (!buffer || !func_pointer(buffer, &buffer_size)) { return false; } + if (!buffer || !func_pointer(buffer, &buffer_size)) { + return false; + } buffer_position = buffer; while (offset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= buffer_size) { @@ -117,7 +127,9 @@ bool RetrieveCacheSize(int64_t* cache_sizes) { buffer_position++; } - if (buffer) { free(buffer); } + if (buffer) { + free(buffer); + } return true; } #endif @@ -125,7 +137,9 @@ bool RetrieveCacheSize(int64_t* cache_sizes) { void CpuInfo::Init() { std::lock_guard<std::mutex> cpuinfo_lock(cpuinfo_mutex); - if (initialized()) { return; } + if (initialized()) { + return; + } string line; string name; @@ -186,7 +200,9 @@ void CpuInfo::Init() { cache_sizes_[i] = data[i]; } #elif _WIN32 - if (!RetrieveCacheSize(cache_sizes_)) { SetDefaultCacheSize(); } + if (!RetrieveCacheSize(cache_sizes_)) { + SetDefaultCacheSize(); + } #else SetDefaultCacheSize(); #endif http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/decimal.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/decimal.cc b/cpp/src/arrow/util/decimal.cc index 72ede35..1a12e20 100644 --- a/cpp/src/arrow/util/decimal.cc +++ b/cpp/src/arrow/util/decimal.cc @@ -21,8 +21,8 @@ namespace arrow { namespace decimal { template <typename T> -ARROW_EXPORT Status FromString( - const std::string& s, Decimal<T>* out, int* precision, int* scale) { +ARROW_EXPORT Status FromString(const std::string& s, Decimal<T>* out, int* precision, + int* scale) { // Implements this regex: "(\\+?|-?)((0*)(\\d*))(\\.(\\d+))?"; if (s.empty()) { return Status::Invalid("Empty string cannot be converted to decimal"); @@ -34,7 +34,9 @@ ARROW_EXPORT Status FromString( char first_char = *charp; if (first_char == '+' || first_char == '-') { - if (first_char == '-') { sign = -1; } + if (first_char == '-') { + sign = -1; + } ++charp; } @@ -55,7 +57,9 @@ ARROW_EXPORT Status FromString( // all zeros and no decimal point if (charp == end) { - if (out != nullptr) { out->value = static_cast<T>(0); } + if (out != nullptr) { + out->value = static_cast<T>(0); + } // Not sure what other libraries assign precision to for this case (this case of // a string consisting only of one or more zeros) @@ -63,7 +67,9 @@ ARROW_EXPORT Status FromString( *precision = static_cast<int>(charp - numeric_string_start); } - if (scale != nullptr) { *scale = 0; } + if (scale != nullptr) { + *scale = 0; + } return Status::OK(); } @@ -127,22 +133,26 @@ ARROW_EXPORT Status FromString( *precision = static_cast<int>(whole_part.size() + fractional_part.size()); } - if (scale != nullptr) { *scale = static_cast<int>(fractional_part.size()); } + if (scale != nullptr) { + *scale = static_cast<int>(fractional_part.size()); + } - if (out != nullptr) { StringToInteger(whole_part, fractional_part, sign, &out->value); } + if (out != nullptr) { + StringToInteger(whole_part, fractional_part, sign, &out->value); + } return Status::OK(); } -template ARROW_EXPORT Status FromString( - const std::string& s, Decimal32* out, int* precision, int* scale); -template ARROW_EXPORT Status FromString( - const std::string& s, Decimal64* out, int* precision, int* scale); -template ARROW_EXPORT Status FromString( - const std::string& s, Decimal128* out, int* precision, int* scale); +template ARROW_EXPORT Status FromString(const std::string& s, Decimal32* out, + int* precision, int* scale); +template ARROW_EXPORT Status FromString(const std::string& s, Decimal64* out, + int* precision, int* scale); +template ARROW_EXPORT Status FromString(const std::string& s, Decimal128* out, + int* precision, int* scale); -void StringToInteger( - const std::string& whole, const std::string& fractional, int8_t sign, int32_t* out) { +void StringToInteger(const std::string& whole, const std::string& fractional, int8_t sign, + int32_t* out) { DCHECK(sign == -1 || sign == 1); DCHECK_NE(out, nullptr); DCHECK(!whole.empty() || !fractional.empty()); @@ -150,12 +160,14 @@ void StringToInteger( *out = std::stoi(whole, nullptr, 10) * static_cast<int32_t>(pow(10.0, static_cast<double>(fractional.size()))); } - if (!fractional.empty()) { *out += std::stoi(fractional, nullptr, 10); } + if (!fractional.empty()) { + *out += std::stoi(fractional, nullptr, 10); + } *out *= sign; } -void StringToInteger( - const std::string& whole, const std::string& fractional, int8_t sign, int64_t* out) { +void StringToInteger(const std::string& whole, const std::string& fractional, int8_t sign, + int64_t* out) { DCHECK(sign == -1 || sign == 1); DCHECK_NE(out, nullptr); DCHECK(!whole.empty() || !fractional.empty()); @@ -163,12 +175,14 @@ void StringToInteger( *out = static_cast<int64_t>(std::stoll(whole, nullptr, 10)) * static_cast<int64_t>(pow(10.0, static_cast<double>(fractional.size()))); } - if (!fractional.empty()) { *out += std::stoll(fractional, nullptr, 10); } + if (!fractional.empty()) { + *out += std::stoll(fractional, nullptr, 10); + } *out *= sign; } -void StringToInteger( - const std::string& whole, const std::string& fractional, int8_t sign, int128_t* out) { +void StringToInteger(const std::string& whole, const std::string& fractional, int8_t sign, + int128_t* out) { DCHECK(sign == -1 || sign == 1); DCHECK_NE(out, nullptr); DCHECK(!whole.empty() || !fractional.empty()); @@ -200,7 +214,9 @@ void FromBytes(const uint8_t* bytes, bool is_negative, Decimal128* decimal) { int128_t::backend_type& backend(decimal_value.backend()); backend.resize(LIMBS_IN_INT128, LIMBS_IN_INT128); std::memcpy(backend.limbs(), bytes, BYTES_IN_128_BITS); - if (is_negative) { decimal->value = -decimal->value; } + if (is_negative) { + decimal->value = -decimal->value; + } } void ToBytes(const Decimal32& value, uint8_t** bytes) { http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/decimal.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/decimal.h b/cpp/src/arrow/util/decimal.h index 0d84ba8..20142fa 100644 --- a/cpp/src/arrow/util/decimal.h +++ b/cpp/src/arrow/util/decimal.h @@ -37,16 +37,16 @@ using boost::multiprecision::int128_t; template <typename T> struct ARROW_EXPORT Decimal; -ARROW_EXPORT void StringToInteger( - const std::string& whole, const std::string& fractional, int8_t sign, int32_t* out); -ARROW_EXPORT void StringToInteger( - const std::string& whole, const std::string& fractional, int8_t sign, int64_t* out); -ARROW_EXPORT void StringToInteger( - const std::string& whole, const std::string& fractional, int8_t sign, int128_t* out); +ARROW_EXPORT void StringToInteger(const std::string& whole, const std::string& fractional, + int8_t sign, int32_t* out); +ARROW_EXPORT void StringToInteger(const std::string& whole, const std::string& fractional, + int8_t sign, int64_t* out); +ARROW_EXPORT void StringToInteger(const std::string& whole, const std::string& fractional, + int8_t sign, int128_t* out); template <typename T> ARROW_EXPORT Status FromString(const std::string& s, Decimal<T>* out, - int* precision = nullptr, int* scale = nullptr); + int* precision = nullptr, int* scale = nullptr); template <typename T> struct ARROW_EXPORT Decimal { @@ -85,8 +85,8 @@ struct ARROW_EXPORT DecimalPrecision<int128_t> { }; template <typename T> -ARROW_EXPORT std::string ToString( - const Decimal<T>& decimal_value, int precision, int scale) { +ARROW_EXPORT std::string ToString(const Decimal<T>& decimal_value, int precision, + int scale) { T value = decimal_value.value; // Decimal values are sent to clients as strings so in the interest of @@ -108,8 +108,8 @@ ARROW_EXPORT std::string ToString( if (scale > 0) { int remaining_scale = scale; do { - str[--last_char_idx] = static_cast<char>( - (remaining_value % 10) + static_cast<T>('0')); // Ascii offset + str[--last_char_idx] = static_cast<char>((remaining_value % 10) + + static_cast<T>('0')); // Ascii offset remaining_value /= 10; } while (--remaining_scale > 0); str[--last_char_idx] = '.'; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/key_value_metadata.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/key_value_metadata.cc b/cpp/src/arrow/util/key_value_metadata.cc index 8bddd5d..6877a6a 100644 --- a/cpp/src/arrow/util/key_value_metadata.cc +++ b/cpp/src/arrow/util/key_value_metadata.cc @@ -48,8 +48,8 @@ KeyValueMetadata::KeyValueMetadata( const std::unordered_map<std::string, std::string>& map) : keys_(UnorderedMapKeys(map)), values_(UnorderedMapValues(map)) {} -KeyValueMetadata::KeyValueMetadata( - const std::vector<std::string>& keys, const std::vector<std::string>& values) +KeyValueMetadata::KeyValueMetadata(const std::vector<std::string>& keys, + const std::vector<std::string>& values) : keys_(keys), values_(values) { DCHECK_EQ(keys.size(), values.size()); } http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/key_value_metadata.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/key_value_metadata.h b/cpp/src/arrow/util/key_value_metadata.h index a2a4623..3d60213 100644 --- a/cpp/src/arrow/util/key_value_metadata.h +++ b/cpp/src/arrow/util/key_value_metadata.h @@ -32,8 +32,8 @@ namespace arrow { class ARROW_EXPORT KeyValueMetadata { public: KeyValueMetadata(); - KeyValueMetadata( - const std::vector<std::string>& keys, const std::vector<std::string>& values); + KeyValueMetadata(const std::vector<std::string>& keys, + const std::vector<std::string>& values); explicit KeyValueMetadata(const std::unordered_map<std::string, std::string>& map); virtual ~KeyValueMetadata() = default; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/logging.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/logging.h b/cpp/src/arrow/util/logging.h index 0edaa9d..89e69f9 100644 --- a/cpp/src/arrow/util/logging.h +++ b/cpp/src/arrow/util/logging.h @@ -50,32 +50,25 @@ namespace arrow { #define DCHECK(condition) \ ARROW_IGNORE_EXPR(condition) \ - while (false) \ - ::arrow::internal::NullLog() + while (false) ::arrow::internal::NullLog() #define DCHECK_EQ(val1, val2) \ ARROW_IGNORE_EXPR(val1) \ - while (false) \ - ::arrow::internal::NullLog() + while (false) ::arrow::internal::NullLog() #define DCHECK_NE(val1, val2) \ ARROW_IGNORE_EXPR(val1) \ - while (false) \ - ::arrow::internal::NullLog() + while (false) ::arrow::internal::NullLog() #define DCHECK_LE(val1, val2) \ ARROW_IGNORE_EXPR(val1) \ - while (false) \ - ::arrow::internal::NullLog() + while (false) ::arrow::internal::NullLog() #define DCHECK_LT(val1, val2) \ ARROW_IGNORE_EXPR(val1) \ - while (false) \ - ::arrow::internal::NullLog() + while (false) ::arrow::internal::NullLog() #define DCHECK_GE(val1, val2) \ ARROW_IGNORE_EXPR(val1) \ - while (false) \ - ::arrow::internal::NullLog() + while (false) ::arrow::internal::NullLog() #define DCHECK_GT(val1, val2) \ ARROW_IGNORE_EXPR(val1) \ - while (false) \ - ::arrow::internal::NullLog() + while (false) ::arrow::internal::NullLog() #else #define ARROW_DFATAL ARROW_FATAL @@ -107,8 +100,12 @@ class CerrLog { has_logged_(false) {} virtual ~CerrLog() { - if (has_logged_) { std::cerr << std::endl; } - if (severity_ == ARROW_FATAL) { std::exit(1); } + if (has_logged_) { + std::cerr << std::endl; + } + if (severity_ == ARROW_FATAL) { + std::exit(1); + } } template <class T> @@ -133,7 +130,9 @@ class FatalLog : public CerrLog { : CerrLog(ARROW_FATAL){} // NOLINT [[noreturn]] ~FatalLog() { - if (has_logged_) { std::cerr << std::endl; } + if (has_logged_) { + std::cerr << std::endl; + } std::exit(1); } }; http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/memory.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/memory.h b/cpp/src/arrow/util/memory.h index c5c17ef..fce9e19 100644 --- a/cpp/src/arrow/util/memory.h +++ b/cpp/src/arrow/util/memory.h @@ -31,7 +31,7 @@ uint8_t* pointer_logical_and(const uint8_t* address, uintptr_t bits) { // A helper function for doing memcpy with multiple threads. This is required // to saturate the memory bandwidth of modern cpus. void parallel_memcopy(uint8_t* dst, const uint8_t* src, int64_t nbytes, - uintptr_t block_size, int num_threads) { + uintptr_t block_size, int num_threads) { std::vector<std::thread> threadpool(num_threads); uint8_t* left = pointer_logical_and(src + block_size - 1, ~(block_size - 1)); uint8_t* right = pointer_logical_and(src + nbytes, ~(block_size - 1)); @@ -52,15 +52,17 @@ void parallel_memcopy(uint8_t* dst, const uint8_t* src, int64_t nbytes, // Start all threads first and handle leftovers while threads run. for (int i = 0; i < num_threads; i++) { - threadpool[i] = std::thread( - memcpy, dst + prefix + i * chunk_size, left + i * chunk_size, chunk_size); + threadpool[i] = std::thread(memcpy, dst + prefix + i * chunk_size, + left + i * chunk_size, chunk_size); } memcpy(dst, src, prefix); memcpy(dst + prefix + num_threads * chunk_size, right, suffix); for (auto& t : threadpool) { - if (t.joinable()) { t.join(); } + if (t.joinable()) { + t.join(); + } } } http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/random.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/random.h b/cpp/src/arrow/util/random.h index 31f2b06..ec48d5d 100644 --- a/cpp/src/arrow/util/random.h +++ b/cpp/src/arrow/util/random.h @@ -27,7 +27,9 @@ class Random { public: explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) { // Avoid bad seeds. - if (seed_ == 0 || seed_ == random_internal::M) { seed_ = 1; } + if (seed_ == 0 || seed_ == random_internal::M) { + seed_ = 1; + } } // Next pseudo-random 32-bit unsigned integer. @@ -48,7 +50,9 @@ class Random { // The first reduction may overflow by 1 bit, so we may need to // repeat. mod == M is not possible; using > allows the faster // sign-bit-based test. - if (seed_ > random_internal::M) { seed_ -= random_internal::M; } + if (seed_ > random_internal::M) { + seed_ -= random_internal::M; + } return seed_; } @@ -97,9 +101,9 @@ class Random { double Normal(double mean, double std_dev) { double uniform1 = (Next() + 1.0) / (random_internal::M + 1.0); double uniform2 = (Next() + 1.0) / (random_internal::M + 1.0); - return ( - mean + - std_dev * sqrt(-2 * ::log(uniform1)) * cos(random_internal::kTwoPi * uniform2)); + return (mean + + std_dev * sqrt(-2 * ::log(uniform1)) * + cos(random_internal::kTwoPi * uniform2)); } // Return a random number between 0.0 and 1.0 inclusive. http://git-wip-us.apache.org/repos/asf/arrow/blob/07b89bf3/cpp/src/arrow/util/rle-encoding-test.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/rle-encoding-test.cc b/cpp/src/arrow/util/rle-encoding-test.cc index 7c9b33c..7549b87 100644 --- a/cpp/src/arrow/util/rle-encoding-test.cc +++ b/cpp/src/arrow/util/rle-encoding-test.cc @@ -178,7 +178,7 @@ TEST(BitArray, TestMixed) { // exactly 'expected_encoding'. // if expected_len is not -1, it will validate the encoded size is correct. void ValidateRle(const vector<int>& values, int bit_width, uint8_t* expected_encoding, - int expected_len) { + int expected_len) { const int len = 64 * 1024; uint8_t buffer[len]; EXPECT_LE(expected_len, len); @@ -190,7 +190,9 @@ void ValidateRle(const vector<int>& values, int bit_width, uint8_t* expected_enc } int encoded_len = encoder.Flush(); - if (expected_len != -1) { EXPECT_EQ(encoded_len, expected_len); } + if (expected_len != -1) { + EXPECT_EQ(encoded_len, expected_len); + } if (expected_encoding != NULL) { EXPECT_EQ(memcmp(buffer, expected_encoding, expected_len), 0); } @@ -211,7 +213,7 @@ void ValidateRle(const vector<int>& values, int bit_width, uint8_t* expected_enc RleDecoder decoder(buffer, len, bit_width); vector<int> values_read(values.size()); ASSERT_EQ(values.size(), - decoder.GetBatch(values_read.data(), static_cast<int>(values.size()))); + decoder.GetBatch(values_read.data(), static_cast<int>(values.size()))); EXPECT_EQ(values, values_read); } } @@ -224,7 +226,9 @@ bool CheckRoundTrip(const vector<int>& values, int bit_width) { RleEncoder encoder(buffer, len, bit_width); for (size_t i = 0; i < values.size(); ++i) { bool result = encoder.Put(values[i]); - if (!result) { return false; } + if (!result) { + return false; + } } int encoded_len = encoder.Flush(); int out = 0; @@ -233,7 +237,9 @@ bool CheckRoundTrip(const vector<int>& values, int bit_width) { RleDecoder decoder(buffer, encoded_len, bit_width); for (size_t i = 0; i < values.size(); ++i) { EXPECT_TRUE(decoder.Get(&out)); - if (values[i] != out) { return false; } + if (values[i] != out) { + return false; + } } } @@ -245,7 +251,9 @@ bool CheckRoundTrip(const vector<int>& values, int bit_width) { decoder.GetBatch(values_read.data(), static_cast<int>(values.size()))) { return false; } - if (values != values_read) { return false; } + if (values != values_read) { + return false; + } } return true; @@ -294,8 +302,8 @@ TEST(Rle, SpecificSequences) { ValidateRle(values, 1, expected_buffer, 1 + num_groups); for (int width = 2; width <= MAX_WIDTH; ++width) { int num_values = static_cast<int>(BitUtil::Ceil(100, 8)) * 8; - ValidateRle( - values, width, NULL, 1 + static_cast<int>(BitUtil::Ceil(width * num_values, 8))); + ValidateRle(values, width, NULL, + 1 + static_cast<int>(BitUtil::Ceil(width * num_values, 8))); } } @@ -352,8 +360,7 @@ TEST(Rle, BitWidthZeroLiteral) { // group but flush before finishing. TEST(BitRle, Flush) { vector<int> values; - for (int i = 0; i < 16; ++i) - values.push_back(1); + for (int i = 0; i < 16; ++i) values.push_back(1); values.push_back(0); ValidateRle(values, 1, NULL, -1); values.push_back(1); @@ -385,7 +392,9 @@ TEST(BitRle, Random) { for (int i = 0; i < ngroups; ++i) { int group_size = dist(gen); - if (group_size > max_group_size) { group_size = 1; } + if (group_size > max_group_size) { + group_size = 1; + } for (int i = 0; i < group_size; ++i) { values.push_back(parity); }
