Skip to content

Commit

Permalink
Activate clang format hook (#317)
Browse files Browse the repository at this point in the history
* Activate clang format hook

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Alex-PLACET and pre-commit-ci[bot] authored Dec 23, 2024
1 parent 80ecbe7 commit 029ab32
Show file tree
Hide file tree
Showing 85 changed files with 1,929 additions and 1,897 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.5
#hooks:
# - id: clang-format
hooks:
- id: clang-format
120 changes: 51 additions & 69 deletions examples/builder_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
*/


#include <vector>
#include <array>
#include <tuple>
#include <cassert>
#include <list>
#include <string>
#include <cassert>
#include <tuple>
#include <vector>

#include <sparrow/builder/builder.hpp>

void primitve_array()
{
{
//! [builder_primitive_array]
// using initializer_list
auto arr = sparrow::build({1, 2, 3, 4, 5});
Expand All @@ -27,9 +27,13 @@ void primitve_array()
auto arr3 = sparrow::build(l);
/////////////////////
// using any range
auto iota = std::views::iota(1, 6) | std::views::transform([](int i){
return static_cast<int>(i);
});
auto iota = std::views::iota(1, 6)
| std::views::transform(
[](int i)
{
return static_cast<int>(i);
}
);
auto arr4 = sparrow::build(iota);
/////////////////////
// all of the arrays above are equivalent to the manually built array
Expand All @@ -42,8 +46,8 @@ void primitve_array()
}

void primitve_array_with_nulls()
{
//! [builder_primitive_array_with_nulls]
{
//! [builder_primitive_array_with_nulls]
// using initializer_list (here we have to explicitly specify the type when using an
// initializer list with nulls)
auto arr = sparrow::build<sparrow::nullable<int>>({1, 2, sparrow::nullval, 4, 5});
Expand All @@ -57,9 +61,13 @@ void primitve_array_with_nulls()
auto arr3 = sparrow::build(l);
/////////////////////
// using any range
auto iota = std::views::iota(1, 6) | std::views::transform([](int i) -> sparrow::nullable<int> {
return i == 3 ? sparrow::nullable<int>{} : sparrow::nullable<int>{i};
});
auto iota = std::views::iota(1, 6)
| std::views::transform(
[](int i) -> sparrow::nullable<int>
{
return i == 3 ? sparrow::nullable<int>{} : sparrow::nullable<int>{i};
}
);
auto arr4 = sparrow::build(iota);
// all of the arrays above are equivalent to the manually built array
std::vector<std::size_t> where_nulls{2};
Expand All @@ -68,49 +76,45 @@ void primitve_array_with_nulls()
assert(arr == arr2);
assert(arr == arr3);
assert(arr == arr4);
//! [builder_primitive_array_with_nulls]
//! [builder_primitive_array_with_nulls]
}

void list_of_strings()
{
{
//! [builder_list_of_strings]
// [["hello", "world","!"], ["Another", "sentence"]]
std::vector<std::vector<std::string>> v{
{"hello", "world", "!"},
{"Another", "sentence"}
};
std::vector<std::vector<std::string>> v{{"hello", "world", "!"}, {"Another", "sentence"}};
auto arr = sparrow::build(v);
//! [builder_list_of_strings]
}

void list_of_strings_with_nulls()
void list_of_strings_with_nulls()
{
//! [builder_list_of_strings_with_nulls]
// [["hello", "world","!"],NULL , ["Another", "sentence"]]
using string_vector = std::vector<std::string>;
using nullable_string_vector = sparrow::nullable<string_vector>;
std::vector<nullable_string_vector> v{
nullable_string_vector{string_vector{"hello", "world", "!"}},
nullable_string_vector{string_vector{"hello", "world", "!"}},
nullable_string_vector{},
nullable_string_vector{string_vector{"Another", "sentence"}}
};
auto arr = sparrow::build(v);
//! [builder_list_of_strings_with_nulls]
}


void list_of_struct()
{
//! [builder_list_of_struct]
/*
[
[
(1, 2.5),
(1, 2.5),
(2, 3.5)
],
[
(3, 5.5),
(5, 6.5),
(3, 5.5),
(5, 6.5),
(6, 7.5)
],
[
Expand All @@ -119,85 +123,64 @@ void list_of_struct()
]
*/
std::vector<std::vector<std::tuple<int, float>>> v{
{
std::tuple<int, float>{1, 2.5},
std::tuple<int, float>{2, 3.5}
},
{
std::tuple<int, float>{3, 5.5},
std::tuple<int, float>{5, 6.5},
std::tuple<int, float>{6, 7.5}
},
{
std::tuple<int, float>{7, 8.5}
}
{std::tuple<int, float>{1, 2.5}, std::tuple<int, float>{2, 3.5}},
{std::tuple<int, float>{3, 5.5}, std::tuple<int, float>{5, 6.5}, std::tuple<int, float>{6, 7.5}},
{std::tuple<int, float>{7, 8.5}}
};
auto arr = sparrow::build(v);
//! [builder_list_of_struct]
}

void fixed_sized_list_strings()
{
{
//! [builder_fixed_sized_list_strings]
std::vector<std::array<std::string, 2>> v{
{"hello", "world"},
{"Another", "sentence"},
{"This", "is"}
};
std::vector<std::array<std::string, 2>> v{{"hello", "world"}, {"Another", "sentence"}, {"This", "is"}};
auto arr = sparrow::build(v);
//! [builder_fixed_sized_list_strings]
}

void fixed_sized_list_of_union()
{
{
//! [builder_fixed_sized_list_of_union]
using variant_type = std::variant<int, float>;
using array_type = std::array<variant_type, 2>;
std::vector<array_type> v{
{1, 2.5f},
{2, 3.5f},
{3, 4.5f}
};
std::vector<array_type> v{{1, 2.5f}, {2, 3.5f}, {3, 4.5f}};
auto arr = sparrow::build(v);
//! [builder_fixed_sized_list_of_union]
}

void dict_encoded_variable_sized_binary()
{
//! [builder_dict_encoded_variable_sized_binary]
sparrow::dict_encode<std::vector<std::string>> v{
std::vector<std::string>{
"hello",
"world",
"hello",
"world",
"hello",
}
};
sparrow::dict_encode<std::vector<std::string>> v{std::vector<std::string>{
"hello",
"world",
"hello",
"world",
"hello",
}};
auto arr = sparrow::build(v);
//! [builder_dict_encoded_variable_sized_binary]
}

void run_end_encoded_variable_sized_binary()
{
//! [builder_run_end_encoded_variable_sized_binary]
sparrow::run_end_encode<std::vector<std::string>> v{
std::vector<std::string>{
"hello",
"hello",
"hello",
"world",
"world",
}
};
sparrow::run_end_encode<std::vector<std::string>> v{std::vector<std::string>{
"hello",
"hello",
"hello",
"world",
"world",
}};
auto arr = sparrow::build(v);
//! [builder_run_end_encoded_variable_sized_binary]
}

void struct_array()
{
//! [builder_struct_array]
using tuple_type = std::tuple<int, std::array<std::string, 2>, sparrow::nullable<float>>;
using tuple_type = std::tuple<int, std::array<std::string, 2>, sparrow::nullable<float>>;
std::vector<tuple_type> v{
{1, {"hello", "world"}, 2.5f},
{2, {"Another", "sentence"}, sparrow::nullval},
Expand All @@ -210,7 +193,7 @@ void struct_array()
void sparse_union_array()
{
//! [builder_union_array]
using variant_type = std::variant<int, std::array<std::string, 2>, sparrow::nullable<float>>;
using variant_type = std::variant<int, std::array<std::string, 2>, sparrow::nullable<float>>;
std::vector<variant_type> v{
int{1},
std::array<std::string, 2>{{"A", "sentence"}},
Expand All @@ -221,7 +204,6 @@ void sparse_union_array()
//! [builder_union_array]
}


int main()
{
primitve_array();
Expand Down
17 changes: 9 additions & 8 deletions examples/typed_array_high_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* The range can be a range of values or a range of nullable values.
*/

//#include <sparrow/array/array_data.hpp>
// #include <sparrow/array/array_data.hpp>


/*void example_typed_array_of_floats(){
using value_type = float;
std::vector<value_type> data = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
// construct the array
auto array = sparrow::typed_array<value_type>(data);
Expand All @@ -34,7 +34,7 @@ void example_typed_array_of_strings(){
"four",
"five"
};
// construct the array
auto array = sparrow::typed_array<value_type>(data);
Expand All @@ -61,7 +61,7 @@ void example_typed_array_of_strings_from_nullables(){
nullable_type("four"),
nullable_type("five")
};
// construct the array
auto array = sparrow::typed_array<value_type>(data);
Expand All @@ -75,9 +75,10 @@ void example_typed_array_of_strings_from_nullables(){
}
}
}*/
int main() {
//example_typed_array_of_floats();
//example_typed_array_of_strings();
//example_typed_array_of_strings_from_nullables();
int main()
{
// example_typed_array_of_floats();
// example_typed_array_of_strings();
// example_typed_array_of_strings_from_nullables();
return 0;
}
5 changes: 3 additions & 2 deletions examples/typed_array_low_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* The typed_array is created from the array_data and the data is accessed.
*/

//#include <sparrow/array/array_data.hpp>
// #include <sparrow/array/array_data.hpp>

int main() {
int main()
{
/////////////////////////////////////////////////
// create array_data with 5 float32 elements
// where the value at index 2 is missing
Expand Down
12 changes: 7 additions & 5 deletions include/sparrow/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace sparrow
{
template <layout A>
requires (not std::is_lvalue_reference_v<A>)
requires(not std::is_lvalue_reference_v<A>)
array::array(A&& a)

Check warning on line 24 in include/sparrow/array.hpp

View workflow job for this annotation

GitHub Actions / build

include/sparrow/array.hpp:24:22 [cppcoreguidelines-missing-std-forward]

forwarding reference parameter 'a' is never forwarded inside the function body
: p_array(new array_wrapper_impl<A>(std::move(a)))
{
Expand Down Expand Up @@ -107,10 +107,12 @@ struct std::formatter<sparrow::array>

auto format(const sparrow::array& ar, std::format_context& ctx) const
{
return ar.visit([&ctx](const auto& layout)
{
return std::format_to(ctx.out(), "{}", layout);
});
return ar.visit(
[&ctx](const auto& layout)
{
return std::format_to(ctx.out(), "{}", layout);
}
);
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/sparrow/array_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
namespace sparrow
{
SPARROW_API cloning_ptr<array_wrapper> array_factory(arrow_proxy proxy);

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace sparrow

BufferType m_buffers;
std::vector<std::uint8_t*> m_buffers_pointers;

};

constexpr arrow_array_private_data::arrow_array_private_data(BufferType buffers, std::size_t children_size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace sparrow
return true;
/* THE CODE USED TO MAKES WRONG ASSUMPTIONS AND NEEDS TO BE REFACTORED IN A SEPERATE PR*/
}

constexpr bool has_bitmap(data_type dt)
{
switch (dt)
Expand Down
Loading

0 comments on commit 029ab32

Please sign in to comment.