Skip to content

Commit

Permalink
detail
Browse files Browse the repository at this point in the history
  • Loading branch information
DerThorsten committed Nov 15, 2024
1 parent 8d40852 commit f22fb30
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
43 changes: 27 additions & 16 deletions include/sparrow/builder/builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
namespace sparrow
{

namespace detail{
template<class T>
struct builder;
} // namespace detail

template<class T>
auto build(T&& t)
{
return detail::builder<T>::create(std::forward<T>(t));
}


namespace detail
{

template <class T>
concept translates_to_primitive_layout =
std::ranges::input_range<T> &&
Expand Down Expand Up @@ -79,16 +94,10 @@ concept translate_to_variable_sized_binary_layout =
template<class T>
struct builder;

template<class T>
auto build(T&& t)
{
return builder<T>::create(std::forward<T>(t));
}

template< translates_to_primitive_layout T>
struct builder<T>
{
using type = primitive_array<typename maybe_nullable_value_type<std::ranges::range_value_t<T>>::type>;
using type = sparrow::primitive_array<typename maybe_nullable_value_type<std::ranges::range_value_t<T>>::type>;
template<class U>
static type create(U&& t)
{
Expand Down Expand Up @@ -121,7 +130,7 @@ struct builder<T>
template< translate_to_fixed_sized_list_layout T>
struct builder<T>
{
using type = fixed_sized_list_array;
using type = sparrow::fixed_sized_list_array;
constexpr static std::size_t list_size = std::tuple_size_v<mnv_t<std::ranges::range_value_t<T>>>;

template<class U>
Expand All @@ -131,16 +140,16 @@ struct builder<T>

return type(
static_cast<std::uint64_t>(list_size),
array(build(flat_list_view))
//,where_null(t)
array(build(flat_list_view)),
where_null(t)
);
}
};

template< translate_to_struct_layout T>
struct builder<T>
{
using type = struct_array;
using type = sparrow::struct_array;
static constexpr std::size_t n_children = std::tuple_size_v<mnv_t<std::ranges::range_value_t<T>>>;

template<class U>
Expand All @@ -156,8 +165,8 @@ struct builder<T>
});
detyped_children[decltype(i)::value] = array(build(tuple_i_col));
});
return type(std::move(detyped_children)
//, where_null(t)
return type(std::move(detyped_children),
where_null(t)
);
}
};
Expand All @@ -166,7 +175,7 @@ struct builder<T>
template< translate_to_variable_sized_binary_layout T>
struct builder<T>
{
using type = string_array;
using type = sparrow::string_array;

template<class U>
static type create(U && t)
Expand All @@ -180,11 +189,13 @@ struct builder<T>

return type(
std::move(data_buffer),
type::offset_from_sizes(sizes)
//,where_null(t)
type::offset_from_sizes(sizes),
where_null(t)
);
}
};

} // namespace detail


}// namespace sparrow
9 changes: 5 additions & 4 deletions include/sparrow/builder/builder_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@
namespace sparrow
{

namespace detail
namespace detail
{
template <class F, std::size_t... Is>
void for_each_index_impl(F&& f, std::index_sequence<Is...>)
{
// Apply f to each index individually
(f(std::integral_constant<std::size_t, Is>{}), ...);
}
}


template <std::size_t SIZE, class F>
void for_each_index(F&& f)
{
// Use std::forward to preserve value category
detail::for_each_index_impl(std::forward<F>(f), std::make_index_sequence<SIZE>());
for_each_index_impl(std::forward<F>(f), std::make_index_sequence<SIZE>());
}


Expand Down Expand Up @@ -95,7 +95,7 @@ namespace sparrow
};

template<class T>
concept is_nullable_like =(is_nullable_like_generic<T> || is_nullable_v<T>);
concept is_nullable_like =(is_nullable_like_generic<T> || sparrow::is_nullable_v<T>);


template<class T>
Expand Down Expand Up @@ -181,6 +181,7 @@ namespace sparrow
return t | std::views::transform([](auto && v) { return v.get(); });
}

} // namespace detail


} // namespace sparrow

0 comments on commit f22fb30

Please sign in to comment.