Skip to content

Commit 6febf6b

Browse files
committed
rmq as params
1 parent a32d749 commit 6febf6b

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

pysdsl/types/rmq.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ namespace RAC_names {
5353
const char INT_VECTOR_NAME[] = "IntVector";
5454
}
5555

56+
template <typename t_rac, typename t_min_ic>
57+
using general_rmq_sparse_table = py::class_<sdsl::rmq_support_sparse_table<t_rac, t_min_ic::value>>;
58+
5659

5760
inline auto add_rmq_classes(py::module& m) {
5861
m.attr("rmq_sparse_table") = py::dict();
@@ -69,6 +72,16 @@ inline auto add_rmq_classes(py::module& m) {
6972

7073
auto rmq_sparse_tables = for_each_in_tuple(rmq_support_sparse_table_params(),
7174
add_rmq_sparse_table_functor(m, doc_rmq_sparse_table));
75+
76+
////////////// as params //////////////////////
77+
using rmq_support_sparse_table_as_params = std::tuple<
78+
std::tuple<sdsl::int_vector<>, std::integral_constant<bool, true>>,
79+
std::tuple<sdsl::int_vector<>, std::integral_constant<bool, false>>
80+
>;
81+
82+
auto rmq_sparse_tables_as_params = for_each_in_tuple(rmq_support_sparse_table_as_params(),
83+
make_general_sybset_functor<general_rmq_sparse_table>(rmq_sparse_tables));
84+
///////////////////////////////////////////////
7285

7386
return std::tuple_cat(rmq_sparse_tables);
7487
}

pysdsl/util/tupletricks.hpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ decltype(auto) for_each_impl(P&& t, Function&& f, std::index_sequence<Is...>) {
1414

1515
template<typename P, typename Function, std::size_t... Is>
1616
constexpr
17-
decltype(auto) for_each_impl(P& t, Function&& f, std::index_sequence<Is...>) {
17+
decltype(auto) for_each_impl(const P& t, Function&& f, std::index_sequence<Is...>) {
1818
return std::make_tuple(f(std::get<Is>(t))...); }
1919

2020
template<typename... T, typename Function>
@@ -27,6 +27,26 @@ constexpr
2727
decltype(auto) for_each(std::tuple<T...>& t, Function&& f) {
2828
return for_each_impl(t, f, std::index_sequence_for<T...>{}); }
2929

30+
template<typename P, typename Function, std::size_t... Is>
31+
constexpr
32+
decltype(auto) forward_each_impl(P&& t, Function&& f, std::index_sequence<Is...>) {
33+
return std::forward_as_tuple(f(std::get<Is>(t))...); }
34+
35+
template<typename P, typename Function, std::size_t... Is>
36+
constexpr
37+
decltype(auto) forward_each_impl(const P& t, Function&& f, std::index_sequence<Is...>) {
38+
return std::forward_as_tuple(f(std::get<Is>(t))...); }
39+
40+
template<typename... T, typename Function>
41+
constexpr
42+
decltype(auto) forward_each(const std::tuple<T...>& t, Function&& f) {
43+
return forward_each_impl(t, f, std::index_sequence_for<T...>{}); }
44+
45+
template<typename... T, typename Function>
46+
constexpr
47+
decltype(auto) forward_each(std::tuple<T...>& t, Function&& f) {
48+
return forward_each_impl(t, f, std::index_sequence_for<T...>{}); }
49+
3050
} // namespace detail
3151

3252

@@ -40,3 +60,45 @@ template <typename... Ts, typename F>
4060
constexpr
4161
decltype(auto) for_each_in_tuple(std::tuple<Ts...> &t, F f) {
4262
return detail::for_each(t, f); }
63+
64+
template <typename... Ts, typename F>
65+
constexpr
66+
decltype(auto) forward_each_in_tuple(const std::tuple<Ts...> &t, F f) {
67+
return detail::forward_each(t, f); }
68+
69+
70+
template <typename... Ts, typename F>
71+
constexpr
72+
decltype(auto) forward_each_in_tuple(std::tuple<Ts...> &t, F f) {
73+
return detail::forward_each(t, f); }
74+
75+
76+
// subset functor
77+
template <typename T>
78+
struct get_template_arg {
79+
using arg = T;
80+
};
81+
82+
template <typename T, T N>
83+
struct get_template_arg<std::integral_constant<T, N>> {
84+
const static T arg = N;
85+
};
86+
87+
88+
template <template <typename...> typename general_template, typename... Ts>
89+
struct GeneralSubsetFunctor {
90+
std::tuple<Ts...>& tpl;
91+
92+
constexpr GeneralSubsetFunctor(std::tuple<Ts...>& tpl) noexcept
93+
: tpl(tpl) {}
94+
95+
template <typename... Args>
96+
auto& operator()(std::tuple<Args...>) const {
97+
return std::get<general_template<Args...>>(tpl);
98+
}
99+
};
100+
101+
template <template <typename...> typename general_template, typename... Ts>
102+
auto make_general_sybset_functor(std::tuple<Ts...>& tpl) {
103+
return GeneralSubsetFunctor<general_template, Ts...>(tpl);
104+
}

0 commit comments

Comments
 (0)