|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <string> |
| 4 | +#include <tuple> |
| 5 | +#include <utility> |
| 6 | + |
| 7 | +#include <pybind11/pybind11.h> |
| 8 | + |
| 9 | +#include <sdsl/rmq_support_sparse_table.hpp> |
| 10 | + |
| 11 | +#include "operations/sizes.hpp" |
| 12 | +#include "operations/iteration.hpp" |
| 13 | +#include "util/tupletricks.hpp" |
| 14 | +#include "docstrings.hpp" |
| 15 | +#include "io.hpp" |
| 16 | +#include "calc.hpp" |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +struct add_rmq_sparse_table_functor { |
| 21 | + py::module& m; |
| 22 | + const char* doc; |
| 23 | + |
| 24 | + constexpr add_rmq_sparse_table_functor(py::module& m, const char* doc = nullptr) |
| 25 | + : m(m), doc(doc) {} |
| 26 | + |
| 27 | + template <typename t_rac, const char* rac_name, bool t_min> |
| 28 | + decltype(auto) operator()(std::tuple<t_rac, |
| 29 | + std::integral_constant<const char*, rac_name>, |
| 30 | + std::integral_constant<bool, t_min>>) { |
| 31 | + using T = sdsl::rmq_support_sparse_table<t_rac, t_min>; |
| 32 | + |
| 33 | + std::string name = |
| 34 | + std::string("Range") + (t_min ? "Min" : "Max") + "QuerySparseTable_for_" + rac_name; |
| 35 | + |
| 36 | + auto cls = py::class_<T>(m, name.c_str()) |
| 37 | + .def_property_readonly("size", (typename T::size_type(T::*)(void) const)& T::size) |
| 38 | + .def(py::init([](const t_rac* rac) {return T(rac);})) |
| 39 | + .def("__call__", (typename T::size_type(T::*)(typename T::size_type, typename T::size_type) const)& T::operator()); |
| 40 | + |
| 41 | + add_sizes(cls); |
| 42 | + add_description(cls); |
| 43 | + |
| 44 | + // load takes two params |
| 45 | + // add_serialization(cls); |
| 46 | + |
| 47 | + return cls; |
| 48 | + } |
| 49 | +}; |
| 50 | + |
| 51 | + |
| 52 | +namespace RAC_names { |
| 53 | + const char INT_VECTOR_NAME[] = "IntVector"; |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +inline auto add_rmq_classes(py::module& m) { |
| 58 | + m.attr("rmq_sparse_table") = py::dict(); |
| 59 | + |
| 60 | + |
| 61 | + using rmq_support_sparse_table_params = std::tuple< |
| 62 | + std::tuple<sdsl::int_vector<>, |
| 63 | + std::integral_constant<const char*, RAC_names::INT_VECTOR_NAME>, |
| 64 | + std::integral_constant<bool, true>>, |
| 65 | + std::tuple<sdsl::int_vector<>, |
| 66 | + std::integral_constant<const char*, RAC_names::INT_VECTOR_NAME>, |
| 67 | + std::integral_constant<bool, false>> |
| 68 | + >; |
| 69 | + |
| 70 | + auto rmq_sparse_tables = for_each_in_tuple(rmq_support_sparse_table_params(), |
| 71 | + add_rmq_sparse_table_functor(m, doc_rmq_sparse_table)); |
| 72 | + |
| 73 | + return std::tuple_cat(rmq_sparse_tables); |
| 74 | +} |
0 commit comments