Skip to content

Commit

Permalink
Simplify builder holders (AliceO2Group#13384)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf authored Aug 15, 2024
1 parent 2e52880 commit 476a75a
Showing 1 changed file with 16 additions and 59 deletions.
75 changes: 16 additions & 59 deletions Framework/Core/include/Framework/TableBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <memory>
#include <tuple>
#include <type_traits>
#include <concepts>

namespace arrow
{
Expand Down Expand Up @@ -462,10 +463,10 @@ struct CachedInsertion {
int pos = 0;
};

template <size_t I, typename T, template <typename U> typename InsertionPolicy>
struct BuilderHolder : InsertionPolicy<T> {
template <size_t I, typename T, typename P>
struct BuilderHolder : P {
static constexpr size_t index = I;
using Policy = InsertionPolicy<T>;
using Policy = P;
using ArrowType = typename detail::ConversionTraits<T>::ArrowType;
using BuilderType = typename arrow::TypeTraits<ArrowType>::BuilderType;

Expand Down Expand Up @@ -562,60 +563,16 @@ template <class T, std::size_t N>
struct is_bounded_array<std::array<T, N>> : std::true_type {
};

template <size_t I, typename T>
struct HolderTrait {

using Holder = BuilderHolder<I, T, DirectInsertion>;
};

template <size_t I>
struct HolderTrait<I, int8_t> {
using Holder = BuilderHolder<I, int8_t, CachedInsertion>;
};

template <size_t I>
struct HolderTrait<I, uint8_t> {
using Holder = BuilderHolder<I, uint8_t, CachedInsertion>;
};

template <size_t I>
struct HolderTrait<I, uint16_t> {
using Holder = BuilderHolder<I, uint16_t, CachedInsertion>;
};

template <size_t I>
struct HolderTrait<I, int16_t> {
using Holder = BuilderHolder<I, int16_t, CachedInsertion>;
};

template <size_t I>
struct HolderTrait<I, int> {
using Holder = BuilderHolder<I, int, CachedInsertion>;
};

template <size_t I>
struct HolderTrait<I, float> {
using Holder = BuilderHolder<I, float, CachedInsertion>;
};

template <size_t I>
struct HolderTrait<I, double> {
using Holder = BuilderHolder<I, double, CachedInsertion>;
};

template <size_t I>
struct HolderTrait<I, unsigned int> {
using Holder = BuilderHolder<I, unsigned int, CachedInsertion>;
};

template <size_t I>
struct HolderTrait<I, uint64_t> {
using Holder = BuilderHolder<I, uint64_t, CachedInsertion>;
};
template <typename T>
concept BulkInsertable = (std::integral<std::decay<T>> && !std::same_as<bool, std::decay_t<T>>);

template <size_t I>
struct HolderTrait<I, int64_t> {
using Holder = BuilderHolder<I, int64_t, CachedInsertion>;
template <typename T>
struct InsertionTrait {
static consteval DirectInsertion<T> policy()
requires(!BulkInsertable<T>);
static consteval CachedInsertion<T> policy()
requires(BulkInsertable<T>);
using Policy = decltype(policy());
};

/// Helper function to convert a brace-initialisable struct to
Expand Down Expand Up @@ -645,15 +602,15 @@ template <typename... ARGS>
constexpr auto makeHolderTypes()
{
return []<std::size_t... Is>(std::index_sequence<Is...>) {
return std::tuple(typename HolderTrait<Is, ARGS>::Holder(arrow::default_memory_pool())...);
return std::tuple(BuilderHolder<Is, ARGS, typename InsertionTrait<ARGS>::Policy>(arrow::default_memory_pool())...);
}(std::make_index_sequence<sizeof...(ARGS)>{});
}

template <typename... ARGS>
auto makeHolders(arrow::MemoryPool* pool, size_t nRows)
{
return [pool, nRows]<std::size_t... Is>(std::index_sequence<Is...>) {
return new std::tuple(typename HolderTrait<Is, ARGS>::Holder(pool, nRows)...);
return new std::tuple(BuilderHolder<Is, ARGS, typename InsertionTrait<ARGS>::Policy>(pool, nRows)...);
}(std::make_index_sequence<sizeof...(ARGS)>{});
}

Expand All @@ -668,7 +625,7 @@ class TableBuilder
static void throwError(RuntimeErrorRef const& ref);

template <typename... ARGS>
using HoldersTuple = typename std::tuple<typename HolderTrait<0, ARGS>::Holder...>;
using HoldersTuple = typename std::tuple<BuilderHolder<0, ARGS, typename InsertionTrait<ARGS>::Policy>...>;

template <typename... ARGS>
using HoldersTupleIndexed = decltype(makeHolderTypes<ARGS...>());
Expand Down

0 comments on commit 476a75a

Please sign in to comment.