From 2335ab322fe35f67adc511f513d1b16a9d1115e7 Mon Sep 17 00:00:00 2001 From: Alexis Placet Date: Fri, 5 Apr 2024 17:37:19 +0200 Subject: [PATCH] Clang format all files --- include/sparrow/array_data.hpp | 39 +++----- include/sparrow/buffer.hpp | 3 +- include/sparrow/data_type.hpp | 6 +- include/sparrow/dictionary_encoded_layout.hpp | 33 ++++--- include/sparrow/dynamic_bitset.hpp | 49 ++++----- include/sparrow/fixed_size_layout.hpp | 12 +-- include/sparrow/iterator.hpp | 99 +++++++------------ include/sparrow/mp_utils.hpp | 3 +- include/sparrow/sparrow_version.hpp | 1 - .../sparrow/variable_size_binary_layout.hpp | 67 +++++-------- test/main.cpp | 9 +- test/test_array_data.cpp | 16 ++- test/test_buffer.cpp | 29 +++--- test/test_dictionary_encoded_layout.cpp | 39 ++++---- test/test_dynamic_bitset.cpp | 27 +++-- test/test_fixed_size_layout.cpp | 11 ++- test/test_iterator.cpp | 11 +-- test/test_variable_size_binary_layout.cpp | 25 +++-- 18 files changed, 208 insertions(+), 271 deletions(-) diff --git a/include/sparrow/array_data.hpp b/include/sparrow/array_data.hpp index 38e9a9ed..ac4acd95 100644 --- a/include/sparrow/array_data.hpp +++ b/include/sparrow/array_data.hpp @@ -180,7 +180,7 @@ namespace sparrow self_type& operator=(U&& value); void swap(self_type& rhs); - + private: void reset(); @@ -205,34 +205,26 @@ namespace sparrow * return reference proxies when it is dereferenced. */ template - class layout_iterator : public iterator_base - < - layout_iterator, - mpl::constify_t, - typename L::iterator_tag, - std::conditional_t, reference_proxy> - > + class layout_iterator : public iterator_base< + layout_iterator, + mpl::constify_t, + typename L::iterator_tag, + std::conditional_t, reference_proxy>> { public: using self_type = layout_iterator; - using base_type = iterator_base - < + using base_type = iterator_base< self_type, mpl::constify_t, typename L::iterator_tag, - std::conditional_t, reference_proxy> - >; + std::conditional_t, reference_proxy>>; using reference = typename base_type::reference; using difference_type = typename base_type::difference_type; - using value_iterator = std::conditional_t< - is_const, typename L::const_value_iterator, typename L::value_iterator - >; + using value_iterator = std::conditional_t; - using bitmap_iterator = std::conditional_t< - is_const, typename L::const_bitmap_iterator, typename L::bitmap_iterator - >; + using bitmap_iterator = std::conditional_t; layout_iterator() noexcept = default; layout_iterator(value_iterator value_iter, bitmap_iterator bitmap_iter); @@ -275,7 +267,6 @@ namespace sparrow const D1& dlhs = lhs.derived_cast(); const D2& drhs = rhs.derived_cast(); return (dlhs && drhs && (dlhs.value() == drhs.value())) || (!dlhs && !drhs); - } template @@ -400,7 +391,7 @@ namespace sparrow template template U> - auto reference_proxy::operator=(const std::optional& rhs) -> self_type& + auto reference_proxy::operator=(const std::optional& rhs) -> self_type& { update(rhs); return *this; @@ -408,7 +399,7 @@ namespace sparrow template template U> - auto reference_proxy::operator=(std::optional&& rhs) -> self_type& + auto reference_proxy::operator=(std::optional&& rhs) -> self_type& { update(std::move(rhs)); return *this; @@ -487,10 +478,7 @@ namespace sparrow **********************************/ template - layout_iterator::layout_iterator( - value_iterator value_iter, - bitmap_iterator bitmap_iter - ) + layout_iterator::layout_iterator(value_iterator value_iter, bitmap_iterator bitmap_iter) : m_value_iter(value_iter) , m_bitmap_iter(bitmap_iter) { @@ -541,4 +529,3 @@ namespace sparrow return m_value_iter < rhs.m_value_iter && m_bitmap_iter < rhs.m_bitmap_iter; } } - diff --git a/include/sparrow/buffer.hpp b/include/sparrow/buffer.hpp index 0904906a..1b828be2 100644 --- a/include/sparrow/buffer.hpp +++ b/include/sparrow/buffer.hpp @@ -19,8 +19,8 @@ #include #include -#include "sparrow/mp_utils.hpp" #include "sparrow/iterator.hpp" +#include "sparrow/mp_utils.hpp" namespace sparrow { @@ -469,4 +469,3 @@ namespace sparrow { } } - diff --git a/include/sparrow/data_type.hpp b/include/sparrow/data_type.hpp index 8565ee06..e3a88629 100644 --- a/include/sparrow/data_type.hpp +++ b/include/sparrow/data_type.hpp @@ -57,11 +57,13 @@ namespace sparrow { } - constexpr data_type id() const { return m_id; } + constexpr data_type id() const + { + return m_id; + } private: data_type m_id; }; } - diff --git a/include/sparrow/dictionary_encoded_layout.hpp b/include/sparrow/dictionary_encoded_layout.hpp index e643051b..6ebc5cfe 100644 --- a/include/sparrow/dictionary_encoded_layout.hpp +++ b/include/sparrow/dictionary_encoded_layout.hpp @@ -15,10 +15,9 @@ #pragma once #include "sparrow/array_data.hpp" -#include "sparrow/iterator.hpp" #include "sparrow/fixed_size_layout.hpp" -#include "sparrow/mp_utils.hpp" #include "sparrow/iterator.hpp" +#include "sparrow/mp_utils.hpp" namespace sparrow { @@ -41,18 +40,14 @@ namespace sparrow public: using self_type = dictionary_value_iterator; - using base_type = iterator_base< - self_type, - typename SL::value_type, - std::random_access_iterator_tag, - typename SL::const_reference>; + using base_type = iterator_base; using reference = typename base_type::reference; using difference_type = typename base_type::difference_type; using index_iterator = std::conditional_t; using sub_layout = mpl::constify_t; using sub_layout_reference = sub_layout&; - + // `dictionary_value_iterator` needs to be default constructible // to satisfy `dictionary_encoded_layout::const_value_range`'s // constraints. @@ -60,6 +55,7 @@ namespace sparrow dictionary_value_iterator(index_iterator index_it, sub_layout_reference sub_layout_reference); private: + reference dereference() const; void increment(); void decrement(); @@ -105,6 +101,7 @@ namespace sparrow class dictionary_encoded_layout { public: + using self_type = dictionary_encoded_layout; using index_type = IT; using inner_value_type = SL::inner_value_type; @@ -151,7 +148,7 @@ namespace sparrow dictionary_encoded_layout& operator=(const dictionary_encoded_layout&) = delete; dictionary_encoded_layout(dictionary_encoded_layout&&) = delete; dictionary_encoded_layout& operator=(dictionary_encoded_layout&&) = delete; - + size_type size() const; const_reference operator[](size_type i) const; @@ -162,6 +159,7 @@ namespace sparrow const_value_range values() const; private: + const indexes_layout& get_const_indexes_layout() const; const_value_iterator value_cbegin() const; @@ -176,7 +174,8 @@ namespace sparrow std::unique_ptr m_indexes_layout; std::unique_ptr m_sub_layout; - static const const_reference& dummy_const_reference(){ + static const const_reference& dummy_const_reference() + { static const typename sub_layout::inner_value_type dummy_inner_value; static const typename sub_layout::bitmap_type dummy_bitmap(1, false); static const const_reference instance(dummy_inner_value, dummy_bitmap[0]); @@ -192,7 +191,10 @@ namespace sparrow *******************************************/ template - dictionary_value_iterator::dictionary_value_iterator(index_iterator index_it, sub_layout_reference sub_layout_reference) + dictionary_value_iterator::dictionary_value_iterator( + index_iterator index_it, + sub_layout_reference sub_layout_reference + ) : m_index_it(index_it) , m_sub_layout_reference(sub_layout_reference) { @@ -264,10 +266,12 @@ namespace sparrow { assert(i < size()); const auto index = (*m_indexes_layout)[i]; - if (index.has_value()) { + if (index.has_value()) + { return (*m_sub_layout)[index.value()]; } - else { + else + { return dummy_const_reference(); } } @@ -279,7 +283,8 @@ namespace sparrow } template - const typename dictionary_encoded_layout::indexes_layout& dictionary_encoded_layout::get_const_indexes_layout() const + const typename dictionary_encoded_layout::indexes_layout& + dictionary_encoded_layout::get_const_indexes_layout() const { return *const_cast(m_indexes_layout.get()); } diff --git a/include/sparrow/dynamic_bitset.hpp b/include/sparrow/dynamic_bitset.hpp index 823b85be..7daff465 100644 --- a/include/sparrow/dynamic_bitset.hpp +++ b/include/sparrow/dynamic_bitset.hpp @@ -221,7 +221,7 @@ namespace sparrow void assign(bool) noexcept; void set() noexcept; void reset() noexcept; - + bitset_type& m_bitset; block_type& m_block; block_type m_mask; @@ -248,24 +248,20 @@ namespace sparrow * a const iterator. */ template - class bitset_iterator : public iterator_base - < - bitset_iterator, - mpl::constify_t, - std::random_access_iterator_tag, - std::conditional_t> - > + class bitset_iterator : public iterator_base< + bitset_iterator, + mpl::constify_t, + std::random_access_iterator_tag, + std::conditional_t>> { public: - + using self_type = bitset_iterator; - using base_type = iterator_base - < + using base_type = iterator_base< self_type, mpl::constify_t, std::contiguous_iterator_tag, - std::conditional_t> - >; + std::conditional_t>>; using reference = typename base_type::reference; using difference_type = typename base_type::difference_type; @@ -297,7 +293,7 @@ namespace sparrow friend class iterator_access; }; - + /************************************** * dynamic_bitset_base implementation * **************************************/ @@ -439,8 +435,7 @@ namespace sparrow template auto dynamic_bitset_base::compute_block_count(size_type bits_count) const noexcept -> size_type { - return bits_count / s_bits_per_block - + static_cast(bits_count % s_bits_per_block != 0); + return bits_count / s_bits_per_block + static_cast(bits_count % s_bits_per_block != 0); } template @@ -465,12 +460,13 @@ namespace sparrow auto dynamic_bitset_base::count_non_null() const noexcept -> size_type { if (m_buffer.empty()) + { return 0u; + } // Number of bits set to 1 in i for i from 0 to 255. // This can be seen as a mapping "uint8_t -> number of non null bits" - static constexpr unsigned char table[] = - { + static constexpr unsigned char table[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, @@ -491,8 +487,6 @@ namespace sparrow return res; } - - template auto dynamic_bitset_base::count_extra_bits() const noexcept -> size_type { @@ -516,7 +510,7 @@ namespace sparrow { --m_null_count; } - else if(!new_value && old_value) + else if (!new_value && old_value) { ++m_null_count; } @@ -566,10 +560,7 @@ namespace sparrow template dynamic_bitset::dynamic_bitset(size_type n, value_type value) - : base_type( - storage_type(this->compute_block_count(n), value ? ~block_type(0) : 0), - n, - value ? 0u : n) + : base_type(storage_type(this->compute_block_count(n), value ? ~block_type(0) : 0), n, value ? 0u : n) { } @@ -631,7 +622,7 @@ namespace sparrow } return *this; } - + template auto bitset_reference::operator|=(bool rhs) noexcept -> self_type& { @@ -641,7 +632,7 @@ namespace sparrow } return *this; } - + template auto bitset_reference::operator^=(bool rhs) noexcept -> self_type& { @@ -708,7 +699,7 @@ namespace sparrow { assert(m_index < bitset_type::s_bits_per_block); } - + template auto bitset_iterator::dereference() const -> reference { @@ -763,7 +754,7 @@ namespace sparrow else { size_type to_next_block = bitset_type::s_bits_per_block - m_index; - n -= to_next_block; + n -= to_next_block; size_type block_n = n / bitset_type::s_bits_per_block; p_block += block_n + 1; n -= block_n * bitset_type::s_bits_per_block; diff --git a/include/sparrow/fixed_size_layout.hpp b/include/sparrow/fixed_size_layout.hpp index 25b7a253..f3a4866e 100644 --- a/include/sparrow/fixed_size_layout.hpp +++ b/include/sparrow/fixed_size_layout.hpp @@ -15,14 +15,14 @@ #pragma once #include +#include #include #include -#include #include "sparrow/array_data.hpp" -#include "sparrow/iterator.hpp" #include "sparrow/buffer.hpp" #include "sparrow/dynamic_bitset.hpp" +#include "sparrow/iterator.hpp" namespace sparrow { @@ -71,7 +71,7 @@ namespace sparrow using const_iterator = layout_iterator; explicit fixed_size_layout(array_data& data); - + fixed_size_layout(const self_type&) = delete; self_type& operator=(const self_type&) = delete; fixed_size_layout(self_type&&) = delete; @@ -117,7 +117,7 @@ namespace sparrow const array_data& data_ref() const; std::reference_wrapper m_data; - + friend class reference_proxy; friend class const_reference_proxy; }; @@ -294,6 +294,4 @@ namespace sparrow return m_data.get(); } -} // namespace sparrow - - +} // namespace sparrow diff --git a/include/sparrow/iterator.hpp b/include/sparrow/iterator.hpp index 9d1f92b2..f2014162 100644 --- a/include/sparrow/iterator.hpp +++ b/include/sparrow/iterator.hpp @@ -90,14 +90,7 @@ namespace sparrow // output_iterator_tag and input_iterator_tag are not supported. // This allows a lot of simplifications regarding the definitions of // postfix increment operators and related methods. - template - < - class Derived, - class IteratorConcept, - class Element, - class Reference, - class Difference - > + template class iterator_root_base; // Utility class for accessing private methods @@ -128,12 +121,13 @@ namespace sparrow it.advance(n); } -#if _WIN32 // Workaround for access issue with msvc, when friend is involved +#if _WIN32 // Workaround for access issue with msvc, when friend is involved + public: + #endif template - static typename It::difference_type - distance_to(const It& lhs, const It& rhs) + static typename It::difference_type distance_to(const It& lhs, const It& rhs) { return lhs.distance_to(rhs); } @@ -149,8 +143,10 @@ namespace sparrow { return lhs.less_than(rhs); } -#if _WIN32 // Workaround for access issue with msvc, when friend is involved +#if _WIN32 // Workaround for access issue with msvc, when friend is involved + private: + #endif template friend class iterator_root_base; @@ -166,13 +162,7 @@ namespace sparrow }; // Specialization of iterator_root_base for forward iterator. - template - < - class Derived, - class Element, - class Reference, - class Difference - > + template class iterator_root_base { private: @@ -231,13 +221,7 @@ namespace sparrow }; // Specialization of iterator_root_base for bidirectional iterator. - template - < - class Derived, - class Element, - class Reference, - class Difference - > + template class iterator_root_base : public iterator_root_base { @@ -263,13 +247,7 @@ namespace sparrow }; // Specialization of iterator_root_base for random access iterator. - template - < - class Derived, - class Element, - class Reference, - class Difference - > + template class iterator_root_base : public iterator_root_base { @@ -324,20 +302,23 @@ namespace sparrow friend inline std::strong_ordering operator<=>(const derived_type& lhs, const derived_type& rhs) { - if (iterator_access::less_than(lhs, rhs)) { return std::strong_ordering::less; } - else if (iterator_access::equal(lhs, rhs)) { return std::strong_ordering::equal; } - else { return std::strong_ordering::greater; } + if (iterator_access::less_than(lhs, rhs)) + { + return std::strong_ordering::less; + } + else if (iterator_access::equal(lhs, rhs)) + { + return std::strong_ordering::equal; + } + else + { + return std::strong_ordering::greater; + } } }; // Specialization of iterator_root_base for contiguous iterator. - template - < - class Derived, - class Element, - class Reference, - class Difference - > + template class iterator_root_base : public iterator_root_base { @@ -351,7 +332,6 @@ namespace sparrow using iterator_concept = std::contiguous_iterator_tag; }; - /* * @class iterator_base * @brief Base class for iterator @@ -389,16 +369,8 @@ namespace sparrow * (except for contiguous_iterator, where it is `random_access_iterator_tag`). This can be overloaded * in the inheriting iterator class. */ - template - < - class Derived, - class Element, - class IteratorConcept, - class Reference = Element&, - class Difference = std::ptrdiff_t - > - class iterator_base - : public iterator_root_base + template + class iterator_base : public iterator_root_base { }; @@ -411,17 +383,14 @@ namespace sparrow * inherit from this class and redefine the private methods * they need only. */ - template - < + template < class Derived, class Iter, class Element, class IteratorConcept = typename std::iterator_traits::iterator_category, class Reference = std::iter_reference_t, - class Difference = std::iter_difference_t - > - class iterator_adaptor - : public iterator_base + class Difference = std::iter_difference_t> + class iterator_adaptor : public iterator_base { public: @@ -432,6 +401,7 @@ namespace sparrow using iterator_type = Iter; iterator_adaptor() = default; + explicit iterator_adaptor(const iterator_type& iter) : p_iter(iter) { @@ -478,7 +448,7 @@ namespace sparrow { return p_iter < rhs.p_iter; } - + iterator_type p_iter = {}; friend class iterator_access; @@ -499,19 +469,20 @@ namespace sparrow : public iterator_adaptor, T*, T, std::contiguous_iterator_tag> { public: - + using self_type = pointer_iterator; using base_type = iterator_adaptor; using iterator_type = typename base_type::iterator_type; - + pointer_iterator() = default; + explicit pointer_iterator(iterator_type p) : base_type(p) { } template - requires std::convertible_to + requires std::convertible_to explicit pointer_iterator(U* u) : base_type(iterator_type(u)) { diff --git a/include/sparrow/mp_utils.hpp b/include/sparrow/mp_utils.hpp index 33da3812..a4e41bca 100644 --- a/include/sparrow/mp_utils.hpp +++ b/include/sparrow/mp_utils.hpp @@ -21,8 +21,7 @@ namespace sparrow namespace mpl { template - struct constify - : std::conditional + struct constify : std::conditional { }; diff --git a/include/sparrow/sparrow_version.hpp b/include/sparrow/sparrow_version.hpp index b69da666..5ebdc79c 100644 --- a/include/sparrow/sparrow_version.hpp +++ b/include/sparrow/sparrow_version.hpp @@ -20,4 +20,3 @@ namespace sparrow constexpr int SPARROW_VERSION_MINOR = 0; constexpr int SPARROW_VERSION_PATCH = 1; } - diff --git a/include/sparrow/variable_size_binary_layout.hpp b/include/sparrow/variable_size_binary_layout.hpp index 5a6c5b7b..5c257dfc 100644 --- a/include/sparrow/variable_size_binary_layout.hpp +++ b/include/sparrow/variable_size_binary_layout.hpp @@ -17,9 +17,9 @@ #include #include -#include "sparrow/mp_utils.hpp" #include "sparrow/array_data.hpp" #include "sparrow/iterator.hpp" +#include "sparrow/mp_utils.hpp" namespace sparrow { @@ -33,39 +33,28 @@ namespace sparrow * @tparam is_const a boolean flag specifying whether this iterator is const. */ template - class vs_binary_value_iterator : public iterator_base - < - vs_binary_value_iterator, - mpl::constify_t, - std::contiguous_iterator_tag, - impl::get_inner_reference_t - > + class vs_binary_value_iterator : public iterator_base< + vs_binary_value_iterator, + mpl::constify_t, + std::contiguous_iterator_tag, + impl::get_inner_reference_t> { public: using self_type = vs_binary_value_iterator; - using base_type = iterator_base - < + using base_type = iterator_base< self_type, mpl::constify_t, std::contiguous_iterator_tag, - impl::get_inner_reference_t - >; + impl::get_inner_reference_t>; using reference = typename base_type::reference; using difference_type = typename base_type::difference_type; - - using offset_iterator = std::conditional_t< - is_const, typename L::const_offset_iterator, typename L::offset_iterator - >; - using data_iterator = std::conditional_t< - is_const, typename L::const_data_iterator, typename L::data_iterator - >; + + using offset_iterator = std::conditional_t; + using data_iterator = std::conditional_t; vs_binary_value_iterator() noexcept = default; - vs_binary_value_iterator( - offset_iterator offset_it, - data_iterator data_begin - ); + vs_binary_value_iterator(offset_iterator offset_it, data_iterator data_begin); private: @@ -99,13 +88,14 @@ namespace sparrow * Let's consider the array of string ['please', 'allow', 'me', 'to', 'introduce', 'myself']. * The internal buffers will be: * - offset: [0, 6, 11, 13, 15, 24, 30] - * - data: ['p','l','e','a','s','e','a','l','l','o','w','m','e','t','o','i','n','t','r','o','d','u','c','e','m','y','s','e','l','f'] - * + * - data: + * ['p','l','e','a','s','e','a','l','l','o','w','m','e','t','o','i','n','t','r','o','d','u','c','e','m','y','s','e','l','f'] + * * @tparam T the type of the data stored in the data buffer, not its byte representation. * @tparam R the reference type to the data. This type is different from the reference type of the layout, * which behaves like std::optional. - * @tparam CR the const reference type to the data. This type is different from the const reference of the layout, - * which behaves like std::optional. + * @tparam CR the const reference type to the data. This type is different from the const reference of the + * layout, which behaves like std::optional. * @tparam OT type of the offset values. Must be std::int64_t or std::int32_t. */ template @@ -134,7 +124,7 @@ namespace sparrow using const_offset_iterator = const OT*; using data_iterator = data_type*; using const_data_iterator = const data_type*; - + using const_value_iterator = vs_binary_value_iterator; using const_bitmap_iterator = array_data::bitmap_type::const_iterator; using const_iterator = layout_iterator; @@ -147,7 +137,7 @@ namespace sparrow // TODO: uncomment the following line and implement the non const overloads // of `begin` and `end` // using iterator = layout_iterator; - + using const_value_range = std::ranges::subrange; using const_bitmap_range = std::ranges::subrange; @@ -157,7 +147,7 @@ namespace sparrow self_type& operator=(const self_type&) = delete; variable_size_binary_layout(self_type&&) = delete; self_type& operator=(self_type&&) = delete; - + size_type size() const; const_reference operator[](size_type i) const; @@ -196,10 +186,7 @@ namespace sparrow *******************************************/ template - vs_binary_value_iterator::vs_binary_value_iterator( - offset_iterator offset_it, - data_iterator data_begin - ) + vs_binary_value_iterator::vs_binary_value_iterator(offset_iterator offset_it, data_iterator data_begin) : m_offset_it(offset_it) , m_data_begin(data_begin) { @@ -256,8 +243,9 @@ namespace sparrow : m_data(data) { assert(data_ref().buffers.size() == 2u); - //TODO: templatize back and front in buffer and uncomment the following line - //assert(data_ref().buffers[0].size() == 0u || data_ref().buffers[0].back() == data_ref().buffers[1].size()); + // TODO: templatize back and front in buffer and uncomment the following line + // assert(data_ref().buffers[0].size() == 0u || data_ref().buffers[0].back() == + // data_ref().buffers[1].size()); } template @@ -273,7 +261,7 @@ namespace sparrow assert(i < size()); return const_reference(value(i), has_value(i)); } - + template auto variable_size_binary_layout::cbegin() const -> const_iterator { @@ -285,7 +273,7 @@ namespace sparrow { return const_iterator(value_cend(), bitmap_cend()); } - + template auto variable_size_binary_layout::bitmap() const -> const_bitmap_range { @@ -331,7 +319,7 @@ namespace sparrow template auto variable_size_binary_layout::value(size_type i) const -> inner_const_reference { - return inner_const_reference(data(*offset(i)), data(*offset(i+1))); + return inner_const_reference(data(*offset(i)), data(*offset(i + 1))); } template @@ -367,4 +355,3 @@ namespace sparrow return m_data.get(); } } - diff --git a/test/main.cpp b/test/main.cpp index 2d6e2e75..f36e5eec 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -13,17 +13,20 @@ // limitations under the License. #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#include "doctest/doctest.h" - #include #include +#include "doctest/doctest.h" + TEST_CASE("version is readable") { // TODO: once available on OSX, use `` facility instead. // We only try to make sure the version valeus are printable, whatever their type. // AKA this is not written to be fancy but to force conversion to string. using namespace sparrow; - [[maybe_unused]] const std::string printable_version = std::string("sparrow version : ") + std::to_string(SPARROW_VERSION_MAJOR) + "." + std::to_string(SPARROW_VERSION_MINOR) + "." + std::to_string(SPARROW_VERSION_PATCH); + [[maybe_unused]] const std::string printable_version = std::string("sparrow version : ") + + std::to_string(SPARROW_VERSION_MAJOR) + "." + + std::to_string(SPARROW_VERSION_MINOR) + "." + + std::to_string(SPARROW_VERSION_PATCH); } diff --git a/test/test_array_data.cpp b/test/test_array_data.cpp index 3691128d..a34b59c7 100644 --- a/test/test_array_data.cpp +++ b/test/test_array_data.cpp @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "doctest/doctest.h" - #include + #include "sparrow/array_data.hpp" +#include "doctest/doctest.h" + namespace sparrow { class mock_layout @@ -35,13 +36,14 @@ namespace sparrow using size_type = std::size_t; mock_layout() = default; + mock_layout(std::initializer_list l) : m_bitmap(l.size()) , m_data(l.size()) { auto bit_iter = m_bitmap.begin(); auto value_iter = m_data.begin(); - for (const auto& v: l) + for (const auto& v : l) { *bit_iter++ = v.has_value(); if (v.has_value()) @@ -91,12 +93,7 @@ namespace sparrow { ref_proxy_fixture() { - m_layout = { - std::make_optional(2), - std::make_optional(5), - std::nullopt, - std::make_optional(7) - }; + m_layout = {std::make_optional(2), std::make_optional(5), std::nullopt, std::make_optional(7)}; } const mock_layout& layout() const @@ -249,4 +246,3 @@ namespace sparrow } } } - diff --git a/test/test_buffer.cpp b/test/test_buffer.cpp index de3dd448..298cd6f4 100644 --- a/test/test_buffer.cpp +++ b/test/test_buffer.cpp @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "doctest/doctest.h" - #include #include "sparrow/buffer.hpp" +#include "doctest/doctest.h" + namespace sparrow { using buffer_test_type = buffer; @@ -106,12 +106,12 @@ namespace sparrow TEST_CASE("empty") { - buffer_test_type b1; - CHECK(b1.empty()); + buffer_test_type b1; + CHECK(b1.empty()); - const std::size_t size = 4u; - buffer_test_type b2(make_test_buffer(size), size); - CHECK(!b2.empty()); + const std::size_t size = 4u; + buffer_test_type b2(make_test_buffer(size), size); + CHECK(!b2.empty()); } TEST_CASE("operator[]") @@ -119,7 +119,7 @@ namespace sparrow const std::size_t size = 4u; buffer_test_type b1(make_test_buffer(size), size); const buffer_test_type b2(b1); - for(std::size_t i = 0; i < size; ++i) + for (std::size_t i = 0; i < size; ++i) { CHECK_EQ(b1[i], i); CHECK_EQ(b2[i], i); @@ -150,7 +150,7 @@ namespace sparrow { const std::size_t size = 4u; buffer_test_type b1(make_test_buffer(size), size); - + const uint8_t expected_value = 101; const std::size_t idx = 3u; b1.data()[idx] = expected_value; @@ -193,7 +193,7 @@ namespace sparrow { const std::size_t size1 = 4u; const std::size_t size2 = 8u; - buffer_test_type b(make_test_buffer(size1), size1); + buffer_test_type b(make_test_buffer(size1), size1); b.resize(size2); CHECK_EQ(b.size(), size2); CHECK_EQ(b.data()[2], 2); @@ -211,7 +211,7 @@ namespace sparrow TEST_CASE("clear") { const std::size_t size1 = 4u; - buffer_test_type b(make_test_buffer(size1), size1); + buffer_test_type b(make_test_buffer(size1), size1); b.clear(); CHECK_EQ(b.size(), 0u); } @@ -239,8 +239,8 @@ namespace sparrow auto citer = b.crbegin(); for (std::size_t i = b.size(); i != 0u; --i) { - CHECK_EQ(*iter++, b[i-1]); - CHECK_EQ(*citer++, b[i-1]); + CHECK_EQ(*iter++, b[i - 1]); + CHECK_EQ(*citer++, b[i - 1]); } CHECK_EQ(iter, b.rend()); CHECK_EQ(citer, b.crend()); @@ -256,9 +256,8 @@ namespace sparrow uint8_t* mem = make_test_buffer(size); [[maybe_unused]] view_test_type v(mem, size); } - + { - const std::size_t size = 8u; buffer_test_type b(make_test_buffer(size), size); [[maybe_unused]] view_test_type v(b); diff --git a/test/test_dictionary_encoded_layout.cpp b/test/test_dictionary_encoded_layout.cpp index 66e72d03..d32221a5 100644 --- a/test/test_dictionary_encoded_layout.cpp +++ b/test/test_dictionary_encoded_layout.cpp @@ -12,21 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "doctest/doctest.h" - #include +#include #include +#include // For doctest #include #include -#include -#include // For doctest -#include "sparrow/variable_size_binary_layout.hpp" #include "sparrow/dictionary_encoded_layout.hpp" +#include "sparrow/variable_size_binary_layout.hpp" + +#include "doctest/doctest.h" using data_type_t = uint8_t; constexpr size_t element_count = 10; -static const std::array indexes {1, 0,3, 0, 1, 2, 3, 2, 4, 2}; +static const std::array indexes{1, 0, 3, 0, 1, 2, 3, 2, 4, 2}; namespace sparrow { @@ -39,7 +39,7 @@ namespace sparrow m_data.bitmap.set(9, false); constexpr size_t buffer_size = (element_count * sizeof(data_type_t)) / sizeof(uint8_t); buffer b(buffer_size); - std::ranges::copy(indexes,b.data()); + std::ranges::copy(indexes, b.data()); m_data.buffers.push_back(b); m_data.length = element_count; auto dictionary = make_dictionary(); @@ -53,15 +53,24 @@ namespace sparrow dictionary.buffers.resize(2); dictionary.buffers[0].resize(sizeof(std::int64_t) * (words.size() + 1)); dictionary.buffers[1].resize(std::accumulate( - words.cbegin(), words.cend(), size_t(0), [](std::size_t res, const auto& s) { return res + s.size(); } + words.cbegin(), + words.cend(), + size_t(0), + [](std::size_t res, const auto& s) + { + return res + s.size(); + } )); dictionary.buffers[0].data()[0] = 0u; auto iter = dictionary.buffers[1].begin(); - const auto offset = [&dictionary](){ return dictionary.buffers[0].data(); }; + const auto offset = [&dictionary]() + { + return dictionary.buffers[0].data(); + }; for (size_t i = 0; i < words.size(); ++i) { - offset()[i+1] = offset()[i] + words[i].size(); + offset()[i + 1] = offset()[i] + words[i].size(); std::ranges::copy(words[i], iter); iter += words[i].size(); dictionary.bitmap.set(i, true); @@ -73,14 +82,7 @@ namespace sparrow return dictionary; } - static constexpr std::array words = - { - "you", - "are", - "not", - "prepared", - "null" - }; + static constexpr std::array words = {"you", "are", "not", "prepared", "null"}; array_data m_data; using sub_layout_type = variable_size_binary_layout; @@ -89,7 +91,6 @@ namespace sparrow TEST_SUITE("dictionary_encoded_layout") { - TEST_CASE_FIXTURE(dictionary_encoded_fixture, "constructors") { CHECK(m_data.buffers.size() == 1); diff --git a/test/test_dynamic_bitset.cpp b/test/test_dynamic_bitset.cpp index 6d93170f..9a856fd3 100644 --- a/test/test_dynamic_bitset.cpp +++ b/test/test_dynamic_bitset.cpp @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "doctest/doctest.h" - #include #include #include "sparrow/dynamic_bitset.hpp" +#include "doctest/doctest.h" + namespace sparrow { struct bitmap_fixture @@ -26,11 +26,11 @@ namespace sparrow bitmap_fixture() { p_buffer = new std::uint8_t[m_block_count]; - p_buffer[0] = 38; // 00100110 - p_buffer[1] = 85; // 01010101 - p_buffer[2] = 53; // 00110101 - p_buffer[3] = 7; // 00000111 - m_null_count = 15; // Last 3 bits of buffer[3] are unused + p_buffer[0] = 38; // 00100110 + p_buffer[1] = 85; // 01010101 + p_buffer[2] = 53; // 00110101 + p_buffer[3] = 7; // 00000111 + m_null_count = 15; // Last 3 bits of buffer[3] are unused } std::uint8_t* p_buffer; @@ -38,7 +38,7 @@ namespace sparrow std::size_t m_size = 29; std::size_t m_null_count; }; - + TEST_SUITE("dynamic_bitset") { using bitmap = dynamic_bitset; @@ -73,7 +73,7 @@ namespace sparrow { bitmap b(p_buffer, m_size); CHECK_EQ(b.data(), p_buffer); - + const bitmap& b2 = b; CHECK_EQ(b2.data(), p_buffer); } @@ -96,9 +96,9 @@ namespace sparrow buf[0] = 37; buf[1] = 2; bitmap b3(buf, expected_block_count * 8); - + b2 = b3; - CHECK_EQ(b2.size() , b3.size()); + CHECK_EQ(b2.size(), b3.size()); CHECK_EQ(b2.null_count(), b3.null_count()); CHECK_NE(b2.data(), b3.data()); for (size_t i = 0; i < expected_block_count; ++i) @@ -210,7 +210,7 @@ namespace sparrow TEST_CASE_FIXTURE(bitmap_fixture, "iterator") { // Does not work because the reference is not bool& - //static_assert(std::random_access_iterator); + // static_assert(std::random_access_iterator); static_assert(std::random_access_iterator); bitmap b(p_buffer, m_size); @@ -263,7 +263,7 @@ namespace sparrow TEST_CASE_FIXTURE(bitmap_fixture, "bitset_reference") { - //as a reminder: p_buffer[0] = 38; // 00100110 + // as a reminder: p_buffer[0] = 38; // 00100110 bitmap b(p_buffer, m_size); auto iter = b.begin(); *iter = true; @@ -292,4 +292,3 @@ namespace sparrow } } } - diff --git a/test/test_fixed_size_layout.cpp b/test/test_fixed_size_layout.cpp index 6965307c..e63bcae5 100644 --- a/test/test_fixed_size_layout.cpp +++ b/test/test_fixed_size_layout.cpp @@ -14,10 +14,10 @@ #include #include -#include "doctest/doctest.h" - #include "sparrow/fixed_size_layout.hpp" +#include "doctest/doctest.h" + namespace sparrow { // TODO: Test all the other base types once #15 is addressed. @@ -127,7 +127,9 @@ namespace sparrow for (std::size_t i = 0; i < lt.size(); ++i) { if (i % 2 != 0) + { lt[i] = std::nullopt; + } } layout_test_type::const_bitmap_iterator citer = lt_bitmap.begin(); @@ -152,14 +154,15 @@ namespace sparrow CHECK_EQ(it, end); - for (auto v: lt) + for (auto v : lt) + { CHECK(v.has_value()); + } array_data ad_empty = make_test_array_data(0, 0); layout_test_type lt_empty(ad_empty); CHECK_EQ(lt_empty.begin(), lt_empty.end()); } - } } diff --git a/test/test_iterator.cpp b/test/test_iterator.cpp index d5d8921e..f91fd3fb 100644 --- a/test/test_iterator.cpp +++ b/test/test_iterator.cpp @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "doctest/doctest.h" - #include #include #include @@ -21,11 +19,12 @@ #include "sparrow/buffer.hpp" #include "sparrow/iterator.hpp" +#include "doctest/doctest.h" + namespace sparrow { - class test_iterator: - public iterator_base + class test_iterator : public iterator_base { public: @@ -247,7 +246,7 @@ namespace sparrow { TEST_CASE("make_pointer_iterator") { - std::array a = { 2, 4, 6 }; + std::array a = {2, 4, 6}; auto iter = make_pointer_iterator(&a[0]); CHECK_EQ(*iter, a[0]); ++iter; @@ -258,7 +257,7 @@ namespace sparrow TEST_CASE("const conversion") { - std::array a = { 2, 4, 6 }; + std::array a = {2, 4, 6}; using iterator = pointer_iterator; using const_iterator = pointer_iterator; diff --git a/test/test_variable_size_binary_layout.cpp b/test/test_variable_size_binary_layout.cpp index 0e629bf8..bae1643b 100644 --- a/test/test_variable_size_binary_layout.cpp +++ b/test/test_variable_size_binary_layout.cpp @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "doctest/doctest.h" - +#include #include #include #include "sparrow/array_data.hpp" #include "sparrow/variable_size_binary_layout.hpp" -#include +#include "doctest/doctest.h" namespace sparrow { @@ -32,13 +31,19 @@ namespace sparrow m_data.buffers.resize(2); m_data.buffers[0].resize(sizeof(std::int64_t) * (nb_words + 1)); m_data.buffers[1].resize(std::accumulate( - words, words + nb_words, 0u, [](std::size_t res, const auto& s) { return res + s.size(); } + words, + words + nb_words, + 0u, + [](std::size_t res, const auto& s) + { + return res + s.size(); + } )); m_data.buffers[0].data()[0] = 0u; auto iter = m_data.buffers[1].begin(); for (size_t i = 0; i < nb_words; ++i) { - offset()[i+1] = offset()[i] + words[i].size(); + offset()[i + 1] = offset()[i] + words[i].size(); std::copy(words[i].cbegin(), words[i].cend(), iter); iter += words[i].size(); m_data.bitmap.set(i, true); @@ -50,18 +55,12 @@ namespace sparrow } static constexpr size_t nb_words = 4u; - static constexpr std::string_view words[nb_words] = - { - "you", - "are", - "not", - "prepared" - }; + static constexpr std::string_view words[nb_words] = {"you", "are", "not", "prepared"}; array_data m_data; // TODO: replace R = std::string_view with specific reference proxy using layout_type = variable_size_binary_layout; - + private: std::int64_t* offset()