Skip to content

Commit

Permalink
Applied clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille committed Jun 28, 2024
1 parent b163b1a commit 41247c3
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 70 deletions.
180 changes: 116 additions & 64 deletions include/sparrow/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace sparrow
using make_typed_array_t = typed_array<T>;

using all_array_types_t = mpl::transform<make_typed_array_t, all_base_types_t>;

struct array_traits
{
using array_variant = mpl::rename<all_array_types_t, std::variant>;
Expand All @@ -41,11 +41,12 @@ namespace sparrow
};

template <bool is_const>
class array_iterator : public iterator_base<
array_iterator<is_const>,
array_traits::value_type,
std::random_access_iterator_tag,
std::conditional_t<is_const, array_traits::const_reference, array_traits::reference>>
class array_iterator
: public iterator_base<
array_iterator<is_const>,
array_traits::value_type,
std::random_access_iterator_tag,
std::conditional_t<is_const, array_traits::const_reference, array_traits::reference>>
{
public:

Expand All @@ -61,9 +62,11 @@ namespace sparrow
array_iterator() = default;

template <class It>
requires (!std::same_as<std::decay_t<It>, array_iterator<is_const>>)
array_iterator(It&& iter) : m_iter(std::forward<It>(iter))
{}
requires(!std::same_as<std::decay_t<It>, array_iterator<is_const>>)
array_iterator(It&& iter)
: m_iter(std::forward<It>(iter))
{
}

private:

Expand All @@ -78,20 +81,14 @@ namespace sparrow
using iterator_storage = std::conditional_t<
is_const,
mpl::transform<array_iterator_t, array_traits::array_variant>,
mpl::transform<array_const_iterator_t, array_traits::array_variant>
>;
mpl::transform<array_const_iterator_t, array_traits::array_variant>>;

using inner_iterator = std::conditional_t<
is_const,
array_traits::inner_const_iterator,
array_traits::inner_iterator
>;
using inner_iterator = std::conditional_t<is_const, array_traits::inner_const_iterator, array_traits::inner_iterator>;
inner_iterator m_iter;

friend class iterator_access;
};


class array
{
public:
Expand Down Expand Up @@ -135,25 +132,49 @@ namespace sparrow
template <bool IC>
auto array_iterator<IC>::dereference() const -> reference
{
return std::visit([](auto&& arg) { return reference(*arg); }, m_iter);
return std::visit(
[](auto&& arg)
{
return reference(*arg);
},
m_iter
);
}

template <bool IC>
void array_iterator<IC>::increment()
{
std::visit([](auto&& arg) { ++arg; }, m_iter);
std::visit(
[](auto&& arg)
{
++arg;
},
m_iter
);
}

template <bool IC>
void array_iterator<IC>::decrement()
{
std::visit([](auto&& arg) { --arg; }, m_iter);
std::visit(
[](auto&& arg)
{
--arg;
},
m_iter
);
}

template <bool IC>
void array_iterator<IC>::advance(difference_type n)
{
std::visit([n](auto&& arg) { arg += n; }, m_iter);
std::visit(
[n](auto&& arg)
{
arg += n;
},
m_iter
);
}

template <bool IC>
Expand Down Expand Up @@ -213,43 +234,43 @@ namespace sparrow

inline auto array::build_array(data_descriptor dd, array_data data) const -> array_variant
{
switch(dd.id())
switch (dd.id())
{
case data_type::NA:
return typed_array<null_type>(std::move(data));
case data_type::BOOL:
return typed_array<bool>(std::move(data));
case data_type::UINT8:
return typed_array<std::uint8_t>(std::move(data));
case data_type::INT8:
return typed_array<std::int8_t>(std::move(data));
case data_type::UINT16:
return typed_array<std::uint16_t>(std::move(data));
case data_type::INT16:
return typed_array<std::int16_t>(std::move(data));
case data_type::UINT32:
return typed_array<std::uint32_t>(std::move(data));
case data_type::INT32:
return typed_array<std::int32_t>(std::move(data));
case data_type::UINT64:
return typed_array<std::uint64_t>(std::move(data));
case data_type::INT64:
return typed_array<std::int64_t>(std::move(data));
case data_type::HALF_FLOAT:
return typed_array<float16_t>(std::move(data));
case data_type::FLOAT:
return typed_array<float32_t>(std::move(data));
case data_type::DOUBLE:
return typed_array<float64_t>(std::move(data));
case data_type::STRING:
case data_type::FIXED_SIZE_BINARY:
return typed_array<std::string>(std::move(data));
case data_type::TIMESTAMP:
return typed_array<sparrow::timestamp>(std::move(data));
default:
// TODO: implement other data types, remove the default use case
// and throw from outside of the switch
throw std::invalid_argument("not supported yet");
case data_type::NA:
return typed_array<null_type>(std::move(data));
case data_type::BOOL:
return typed_array<bool>(std::move(data));
case data_type::UINT8:
return typed_array<std::uint8_t>(std::move(data));
case data_type::INT8:
return typed_array<std::int8_t>(std::move(data));
case data_type::UINT16:
return typed_array<std::uint16_t>(std::move(data));
case data_type::INT16:
return typed_array<std::int16_t>(std::move(data));
case data_type::UINT32:
return typed_array<std::uint32_t>(std::move(data));
case data_type::INT32:
return typed_array<std::int32_t>(std::move(data));
case data_type::UINT64:
return typed_array<std::uint64_t>(std::move(data));
case data_type::INT64:
return typed_array<std::int64_t>(std::move(data));
case data_type::HALF_FLOAT:
return typed_array<float16_t>(std::move(data));
case data_type::FLOAT:
return typed_array<float32_t>(std::move(data));
case data_type::DOUBLE:
return typed_array<float64_t>(std::move(data));
case data_type::STRING:
case data_type::FIXED_SIZE_BINARY:
return typed_array<std::string>(std::move(data));
case data_type::TIMESTAMP:
return typed_array<sparrow::timestamp>(std::move(data));
default:
// TODO: implement other data types, remove the default use case
// and throw from outside of the switch
throw std::invalid_argument("not supported yet");
}
}

Expand All @@ -261,12 +282,24 @@ namespace sparrow

inline bool array::empty() const
{
return std::visit([](auto&& arg) { return arg.empty(); }, m_array);
return std::visit(
[](auto&& arg)
{
return arg.empty();
},
m_array
);
}

inline auto array::size() const -> size_type
{
return std::visit([](auto&& arg) { return arg.size(); }, m_array);
return std::visit(
[](auto&& arg)
{
return arg.size();
},
m_array
);
}

inline auto array::at(size_type i) const -> const_reference
Expand All @@ -275,8 +308,8 @@ namespace sparrow
{
// TODO: Use our own format function
throw std::out_of_range(
"array::at: index out of range for array of size " + std::to_string(size())
+ " at index " + std::to_string(i)
"array::at: index out of range for array of size " + std::to_string(size()) + " at index "
+ std::to_string(i)
);
}
return (*this)[i];
Expand All @@ -285,8 +318,15 @@ namespace sparrow
inline auto array::operator[](size_type i) const -> const_reference
{
SPARROW_ASSERT_TRUE(i < size());
return std::visit([i](auto&& arg) { return const_reference(arg[i]); }, m_array);
return std::visit(
[i](auto&& arg)
{
return const_reference(arg[i]);
},
m_array
);
}

inline auto array::front() const -> const_reference
{
SPARROW_ASSERT_FALSE(empty());
Expand All @@ -311,11 +351,23 @@ namespace sparrow

inline auto array::cbegin() const -> const_iterator
{
return std::visit([](auto&& arg) { return const_iterator(arg.cbegin()); }, m_array);
return std::visit(
[](auto&& arg)
{
return const_iterator(arg.cbegin());
},
m_array
);
}

inline auto array::cend() const -> const_iterator
{
return std::visit([](auto&& arg) { return const_iterator(arg.cend()); }, m_array);
return std::visit(
[](auto&& arg)
{
return const_iterator(arg.cend());
},
m_array
);
}
}
9 changes: 4 additions & 5 deletions test/test_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

#include "sparrow/array.hpp"

#include "doctest/doctest.h"

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

using namespace sparrow;
using sparrow::test::to_value_type;
Expand Down Expand Up @@ -231,11 +230,11 @@ TEST_SUITE("array")
auto iter_end2 = ar.end();
CHECK_EQ(iter_end, iter_end2);

for(std::size_t i = 0; i < ar.size(); ++iter, ++i)
for (std::size_t i = 0; i < ar.size(); ++iter, ++i)
{
CHECK_EQ(std::get<const_ref>(*iter), to_value_type<T>(i + offset));
CHECK_EQ(std::get<const_ref>(*iter), to_value_type<T>(i + offset));
}

CHECK_EQ(iter, iter_end);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_dictionary_encoded_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace sparrow
m_data.dictionary = sparrow::value_ptr<array_data>(std::move(dictionary));
}

static array_data make_dictionary(const std::array<std::string_view ,5>& lwords)
static array_data make_dictionary(const std::array<std::string_view, 5>& lwords)
{
array_data dictionary;
dictionary.bitmap.resize(lwords.size());
Expand Down

0 comments on commit 41247c3

Please sign in to comment.