From 3057e78f33c1c93ba92b4406e924ebe4aac8a89a Mon Sep 17 00:00:00 2001 From: Dmitrii Kamaldinov Date: Sat, 13 Apr 2019 03:06:29 +0300 Subject: [PATCH 1/9] rmq first commit --- pysdsl/types/rmq.hpp | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 pysdsl/types/rmq.hpp diff --git a/pysdsl/types/rmq.hpp b/pysdsl/types/rmq.hpp new file mode 100644 index 0000000..e6a8c3c --- /dev/null +++ b/pysdsl/types/rmq.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include +#include +#include + +#include + +#include + +#include "operations/sizes.hpp" +#include "operations/iteration.hpp" +#include "util/tupletricks.hpp" +#include "docstrings.hpp" +#include "io.hpp" +#include "calc.hpp" + + + +struct add_rmq_sparse_table_functor { + py::module& m; + const char* doc; + + constexpr add_rmq_sparse_table_functor(py::module& m, const char* doc = nullptr) + : m(m), doc(doc) {} + + template + decltype(auto) operator()(std::tuple, + std::integral_constant>) { + using T = sdsl::rmq_support_sparse_table; + + std::string name = + std::string("Range") + (t_min ? "Min" : "Max") + "QuerySparseTable_for_" + rac_name; + + auto cls = py::class_(m, name.c_str()) + .def_property_readonly("size", (typename T::size_type(T::*)(void) const)& T::size) + .def(py::init([](const t_rac* rac) {return T(rac);})) + .def("__call__", (typename T::size_type(T::*)(typename T::size_type, typename T::size_type) const)& T::operator()); + + add_sizes(cls); + add_description(cls); + + // load takes two params + // add_serialization(cls); + + return cls; + } +}; + + +namespace RAC_names { + const char INT_VECTOR_NAME[] = "IntVector"; +} + + +inline auto add_rmq_classes(py::module& m) { + m.attr("rmq_sparse_table") = py::dict(); + + + using rmq_support_sparse_table_params = std::tuple< + std::tuple, + std::integral_constant, + std::integral_constant>, + std::tuple, + std::integral_constant, + std::integral_constant> + >; + + auto rmq_sparse_tables = for_each_in_tuple(rmq_support_sparse_table_params(), + add_rmq_sparse_table_functor(m, doc_rmq_sparse_table)); + + return std::tuple_cat(rmq_sparse_tables); +} From f0b3e7cc7a8b3ad2226df41d1a249970989bbca4 Mon Sep 17 00:00:00 2001 From: Dmitrii Kamaldinov Date: Sat, 13 Apr 2019 03:25:17 +0300 Subject: [PATCH 2/9] rmq as params --- pysdsl/types/rmq.hpp | 13 +++++++++++++ pysdsl/util/tupletricks.hpp | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pysdsl/types/rmq.hpp b/pysdsl/types/rmq.hpp index e6a8c3c..24bc322 100644 --- a/pysdsl/types/rmq.hpp +++ b/pysdsl/types/rmq.hpp @@ -53,6 +53,9 @@ namespace RAC_names { const char INT_VECTOR_NAME[] = "IntVector"; } +template +using general_rmq_sparse_table = py::class_>; + inline auto add_rmq_classes(py::module& m) { m.attr("rmq_sparse_table") = py::dict(); @@ -69,6 +72,16 @@ inline auto add_rmq_classes(py::module& m) { auto rmq_sparse_tables = for_each_in_tuple(rmq_support_sparse_table_params(), add_rmq_sparse_table_functor(m, doc_rmq_sparse_table)); + + ////////////// as params ////////////////////// + using rmq_support_sparse_table_as_params = std::tuple< + std::tuple, std::integral_constant>, + std::tuple, std::integral_constant> + >; + + auto rmq_sparse_tables_as_params = for_each_in_tuple(rmq_support_sparse_table_as_params(), + make_general_sybset_functor(rmq_sparse_tables)); + /////////////////////////////////////////////// return std::tuple_cat(rmq_sparse_tables); } diff --git a/pysdsl/util/tupletricks.hpp b/pysdsl/util/tupletricks.hpp index a1c030f..283d66a 100644 --- a/pysdsl/util/tupletricks.hpp +++ b/pysdsl/util/tupletricks.hpp @@ -91,4 +91,3 @@ template