Skip to content

Commit

Permalink
Clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-PLACET committed Apr 17, 2024
1 parent 8682242 commit d19cbff
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 42 deletions.
32 changes: 21 additions & 11 deletions include/sparrow/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@
#include <compare>

#include "sparrow/config.hpp"

namespace sparrow
{
#if COMPILING_WITH_APPLE_CLANG
#if COMPILING_WITH_APPLE_CLANG

template <typename T>
concept OrdCategory = std::same_as<T, std::strong_ordering> || std::same_as<T, std::weak_ordering>
|| std::same_as<T, std::partial_ordering>;

template <class R1, class R2, class Cmp>
concept LexicographicalComparable = requires(const R1& r1, const R2& r2, Cmp comp)
{
requires std::same_as<decltype(comp(*r1.cbegin(), *r2.cbegin())), std::strong_ordering> ||
std::same_as<decltype(comp(*r1.cbegin(), *r2.cbegin())), std::weak_ordering> ||
std::same_as<decltype(comp(*r1.cbegin(), *r2.cbegin())), std::partial_ordering>;
concept LexicographicalComparable = requires(const R1& r1, const R2& r2, Cmp comp) {
{ r1.cbegin() } -> std::input_or_output_iterator;
{ r2.cbegin() } -> std::input_or_output_iterator;
OrdCategory<decltype(comp(*r1.cbegin(), *r2.cbegin()))>;
};

template <class R1, class R2, class Cmp>
requires LexicographicalComparable<R1, R2, Cmp>
requires LexicographicalComparable<R1, R2, Cmp>
constexpr auto lexicographical_compare_three_way_non_std(const R1& range1, const R2& range2, Cmp comp)
-> decltype(comp(*range1.cbegin(), *range1.cbegin()))
{
Expand All @@ -40,7 +44,7 @@ namespace sparrow
auto iter_2 = range2.cbegin();
const auto end_2 = range2.cend();

while(true)
while (true)
{
if (iter_1 == end_1)
{
Expand All @@ -61,16 +65,22 @@ namespace sparrow
++iter_2;
}
}
#endif
#endif

template <class R1, class R2, class Cmp>
constexpr auto lexicographical_compare_three_way(const R1& range1, const R2& range2, Cmp comp)
-> decltype(comp(*range1.cbegin(), *range2.cbegin()))
{
#if COMPILING_WITH_APPLE_CLANG
return lexicographical_compare_three_way_non_std(range1, range2, comp);
return lexicographical_compare_three_way_non_std(range1, range2, comp);
#else
return std::lexicographical_compare_three_way(range1.cbegin(), range1.cend(), range2.cbegin(), range2.cend(), comp);
return std::lexicographical_compare_three_way(
range1.cbegin(),
range1.cend(),
range2.cbegin(),
range2.cend(),
comp
);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion include/sparrow/array_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ namespace sparrow
const D1& dlhs = lhs.derived_cast();
const D2& drhs = rhs.derived_cast();

using TOrdering = decltype(dlhs.value() <=> drhs.value());
using TOrdering = decltype(dlhs.value() <=> drhs.value());
if (dlhs && drhs)
{
return dlhs.value() <=> drhs.value();
Expand Down
9 changes: 4 additions & 5 deletions include/sparrow/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

#pragma once

consteval bool is_apple_compiler()
{
#if defined(__apple_build_version__)
#define COMPILING_WITH_APPLE_CLANG 1
return true;
#else
#define COMPILING_WITH_APPLE_CLANG 1
return false;
#endif

consteval bool is_apple_compiler() {
return COMPILING_WITH_APPLE_CLANG == 1;
}

constexpr bool COMPILING_WITH_APPLE = is_apple_compiler();
27 changes: 25 additions & 2 deletions include/sparrow/typed_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
#include "sparrow/algorithm.hpp"
#include "sparrow/array_data.hpp"
#include "sparrow/data_traits.hpp"
#include "sparrow/data_type.hpp"

namespace sparrow
{
template <class T, class L = typename arrow_traits<T>::default_layout>
requires is_arrow_base_type<T>
class typed_array
{
public:
Expand Down Expand Up @@ -64,7 +66,7 @@ namespace sparrow
* Access specified element.
*
* Returns a reference to the element at the specified index \p i. No bounds checking is performed.
*
*
* @param i The index of the element to access.
* @pre @p i must be lower than the size of the container.
* @return A reference to the element at the specified index.
Expand Down Expand Up @@ -155,7 +157,7 @@ namespace sparrow
std::partial_ordering operator<=>(const typed_array<T>& other) const;

bool operator==(const typed_array<T>& other) const;

private:

array_data m_data;
Expand All @@ -164,6 +166,7 @@ namespace sparrow

// Constructors
template <class T, class L>
requires is_arrow_base_type<T>
typed_array<T, L>::typed_array(array_data data)
: m_data(std::move(data))
, m_layout(m_data)
Expand All @@ -173,6 +176,7 @@ namespace sparrow
// Element access

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::at(size_type i) -> reference
{
if (i >= size())
Expand All @@ -186,6 +190,7 @@ namespace sparrow
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::at(size_type i) const -> const_reference
{
if (i >= size())
Expand All @@ -199,41 +204,47 @@ namespace sparrow
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::operator[](size_type i) -> reference
{
assert(i < size());
return m_layout[i];
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::operator[](size_type i) const -> const_reference
{
assert(i < size());
return m_layout[i];
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::front() -> reference
{
assert(!empty());
return m_layout[0];
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::front() const -> const_reference
{
assert(!empty());
return m_layout[0];
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::back() -> reference
{
assert(!empty());
return m_layout[size() - 1];
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::back() const -> const_reference
{
assert(!empty());
Expand All @@ -243,48 +254,56 @@ namespace sparrow
// Iterators

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::begin() -> iterator
{
return m_layout.begin();
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::begin() const -> const_iterator
{
return m_layout.cbegin();
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::end() -> iterator
{
return m_layout.end();
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::end() const -> const_iterator
{
return m_layout.cend();
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::cbegin() const -> const_iterator
{
return begin();
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::cend() const -> const_iterator
{
return end();
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::bitmap() const -> const_bitmap_range
{
return m_layout.bitmap();
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::values() const -> const_value_range
{
return m_layout.values();
Expand All @@ -293,12 +312,14 @@ namespace sparrow
// Capacity

template <class T, class L>
requires is_arrow_base_type<T>
bool typed_array<T, L>::empty() const
{
return m_layout.size() == 0;
}

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::size() const -> size_type
{
return m_layout.size();
Expand All @@ -307,12 +328,14 @@ namespace sparrow
// Comparators

template <class T, class L>
requires is_arrow_base_type<T>
auto typed_array<T, L>::operator<=>(const typed_array<T>& other) const -> std::partial_ordering
{
return lexicographical_compare_three_way(*this, other);
}

template <class T, class L>
requires is_arrow_base_type<T>
bool typed_array<T, L>::operator==(const typed_array<T>& other) const
{
return std::equal(cbegin(), cend(), other.cbegin(), other.cend());
Expand Down
24 changes: 13 additions & 11 deletions test/array_data_creation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace sparrow::test
{
/**
* Creates an array_data object for testing purposes.
*
* The bitmap is initialized with all bits set to true, except for the indices specified in the false_bitmap vector.
* The buffer is filled with values from 0 to n-1, where n is the size of the array.
*
*
* The bitmap is initialized with all bits set to true, except for the indices specified in the
* false_bitmap vector. The buffer is filled with values from 0 to n-1, where n is the size of the array.
*
* @tparam T The type of the elements in the array.
* @param n The size of the array.
* @param offset The offset of the array.
Expand All @@ -35,14 +35,15 @@ namespace sparrow::test
* @throws std::invalid_argument If an index in false_bitmap is out of range.
*/
template <typename T>
sparrow::array_data make_test_array_data(size_t n = 10, size_t offset = 0, const std::vector<size_t>& false_bitmap = {})
sparrow::array_data
make_test_array_data(size_t n = 10, size_t offset = 0, const std::vector<size_t>& false_bitmap = {})
{
sparrow::array_data ad;
ad.type = sparrow::data_descriptor(sparrow::arrow_traits<T>::type_id);
ad.bitmap = sparrow::dynamic_bitset<uint8_t>(n, true);
for (const auto i : false_bitmap)
{
if(i >= n)
if (i >= n)
{
throw std::invalid_argument("Index out of range");
}
Expand All @@ -63,15 +64,16 @@ namespace sparrow::test

/**
* Creates an array_data object for testing with std::string elements.
*
*
* @param n The number of elements in the array.
* @param offset The offset value for the array_data object.
* @param false_bitmap A vector of indices to set as false in the bitmap.
* @return The created array_data object.
* @throws std::invalid_argument if any index in false_bitmap is out of range.
*/
template <>
inline sparrow::array_data make_test_array_data<std::string>(size_t n, size_t offset, const std::vector<size_t>& false_bitmap)
inline sparrow::array_data
make_test_array_data<std::string>(size_t n, size_t offset, const std::vector<size_t>& false_bitmap)
{
std::vector<std::string> words;
for (size_t i = 0; i < n; ++i)
Expand Down Expand Up @@ -104,10 +106,10 @@ namespace sparrow::test
iter += words[i].size();
ad.bitmap.set(i, true);
}
for(const auto i : false_bitmap)

for (const auto i : false_bitmap)
{
if(i >= n)
if (i >= n)
{
throw std::invalid_argument("Index out of range");
}
Expand Down
6 changes: 2 additions & 4 deletions test/test_array_data_creation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

#include "sparrow/algorithm.hpp"

#include "doctest/doctest.h"

#include "doctest/doctest.h"
#include "array_data_creation.hpp"
#include "doctest/doctest.h"

TEST_SUITE("array_data_creation")
{
Expand All @@ -32,7 +30,7 @@ TEST_SUITE("array_data_creation")
const sparrow::array_data data = sparrow::test::make_test_array_data<int>(n);
CHECK_EQ(data.length, n);
CHECK_EQ(data.offset, 0);
for(size_t i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
{
CHECK(data.bitmap[i]);
}
Expand Down
Loading

0 comments on commit d19cbff

Please sign in to comment.