@@ -168,15 +168,21 @@ inline auto add_int_class(py::module& m, py::dict& dict, KEY_T key,
168168 return cls;
169169}
170170
171+ template <typename VectorT>
172+ auto add_int_vector (py::module & m, py::dict& int_vectors_dict) {
173+ size_t width = VectorT::fixed_int_width;
174+ std::string name = " Int" + std::to_string (width) + " Vector" ;
175+ return add_int_class<VectorT, typename VectorT::value_type>(
176+ m, int_vectors_dict, width, name.c_str ())
177+ .def (py::init (
178+ [width](size_t size, typename VectorT::value_type default_value) {
179+ return VectorT (size, default_value, width); }),
180+ py::arg (" size" ) = 0 , py::arg (" default_value" ) = 0 );
181+ }
171182
172- inline auto add_int_vectors (py::module & m)
173- {
174- py::dict int_vectors_dict;
175-
176- m.attr (" int_vector" ) = int_vectors_dict;
177-
178- return std::make_tuple (
179- add_int_class<sdsl::int_vector<0 >>(
183+ template <>
184+ auto add_int_vector<sdsl::int_vector<0 >>(py::module & m, py::dict& int_vectors_dict) {
185+ return add_int_class<sdsl::int_vector<0 >>(
180186 m, int_vectors_dict, " dynamic" , " IntVector" , doc_int_vector)
181187 .def (
182188 py::init ([](size_t size,
@@ -198,27 +204,54 @@ inline auto add_int_vectors(py::module& m)
198204 [](sdsl::int_vector<0 > &self) {
199205 sdsl::util::bit_compress (self); },
200206 doc_bit_compress,
201- py::call_guard<py::gil_scoped_release>()),
207+ py::call_guard<py::gil_scoped_release>());
208+ }
202209
203- add_int_class<sdsl::int_vector<1 >, bool >(
210+ template <>
211+ auto add_int_vector<sdsl::int_vector<1 >>(py::module & m, py::dict& int_vectors_dict) {
212+ return add_int_class<sdsl::int_vector<1 >, bool >(
204213 m, int_vectors_dict, 1ul , " BitVector" )
205214 .def (py::init (
206215 [](size_t size, bool default_value) {
207216 return sdsl::int_vector<1 >(size, default_value, 1 ); }),
208217 py::arg (" size" ) = 0 , py::arg (" default_value" ) = false )
209218 .def (" flip" , &sdsl::int_vector<1 >::flip,
210219 " Flip all bits of bit_vector" ,
211- py::call_guard<py::gil_scoped_release>())
212-
213- #define DEF_INC_VECTOR (width, value_type ) ,\
214- add_int_class<sdsl::int_vector<width>, value_type>( \
215- m, int_vectors_dict, width, " Int" #width " Vector" ) \
216- .def (py::init ( \
217- [](size_t size, value_type default_value) { \
218- return sdsl::int_vector<width>(size, default_value, width); }), \
219- py::arg (" size" ) = 0 , py::arg (" default_value" ) = 0 )
220- #include " int_vectors.h"
221- #undef DEF_INC_VECTOR
222- );
220+ py::call_guard<py::gil_scoped_release>());
221+ }
222+
223+
224+ template <typename ... VectorT>
225+ auto make_int_vectors (py::module & m, py::dict& int_vectors_dict) {
226+ return std::make_tuple (add_int_vector<VectorT>(m, int_vectors_dict)...);
227+ }
228+
229+
230+ inline auto add_int_vectors (py::module & m)
231+ {
232+ py::dict int_vectors_dict;
233+
234+ m.attr (" int_vector" ) = int_vectors_dict;
235+
236+ return make_int_vectors<sdsl::int_vector<0 >,
237+ sdsl::int_vector<1 >,
238+ sdsl::int_vector<4 >,
239+ sdsl::int_vector<8 >,
240+ sdsl::int_vector<16 >,
241+ sdsl::int_vector<24 >,
242+ sdsl::int_vector<32 >,
243+ sdsl::int_vector<48 >,
244+ sdsl::int_vector<64 >>(m, int_vectors_dict);
245+
246+ // #define DEF_INC_VECTOR(width, value_type) ,\
247+ // add_int_class<sdsl::int_vector<width>, value_type>( \
248+ // m, int_vectors_dict, width, "Int" #width "Vector") \
249+ // .def(py::init( \
250+ // [](size_t size, value_type default_value) { \
251+ // return sdsl::int_vector<width>(size, default_value, width); }), \
252+ // py::arg("size") = 0, py::arg("default_value") = 0)
253+ // #include "int_vectors.h"
254+ // #undef DEF_INC_VECTOR
255+ // );
223256
224257}
0 commit comments