Skip to content

Commit ee4768f

Browse files
authored
Merge branch 'feature/circleci' into feature/circleci
2 parents 50fd599 + 225956c commit ee4768f

File tree

2 files changed

+56
-48
lines changed

2 files changed

+56
-48
lines changed

pysdsl/types/int_vectors.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DEF_INC_VECTOR(4, uint8_t)
2+
DEF_INC_VECTOR(8, uint8_t)
3+
DEF_INC_VECTOR(16, uint16_t)
4+
DEF_INC_VECTOR(24, uint32_t)
5+
DEF_INC_VECTOR(32, uint32_t)
6+
DEF_INC_VECTOR(48, uint64_t)
7+
DEF_INC_VECTOR(64, uint64_t)

pysdsl/types/intvector.hpp

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -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,59 +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>()),
220+
py::call_guard<py::gil_scoped_release>());
221+
}
212222

213-
add_int_class<sdsl::int_vector<4>, uint16_t>(
214-
m, int_vectors_dict, 4, "Int4Vector")
215-
.def(py::init(
216-
[](size_t size, uint8_t default_value) {
217-
return sdsl::int_vector<4>(size, default_value, 4); }),
218-
py::arg("size") = 0, py::arg("default_value") = 0),
219223

220-
add_int_class<sdsl::int_vector<8>, uint16_t>(
221-
m, int_vectors_dict, 8, "Int8Vector")
222-
.def(py::init(
223-
[](size_t size, uint8_t default_value) {
224-
return sdsl::int_vector<8>(size, default_value, 8); }),
225-
py::arg("size") = 0, py::arg("default_value") = 0),
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+
}
226228

227-
add_int_class<sdsl::int_vector<16>, uint16_t>(
228-
m, int_vectors_dict, 16, "Int16Vector")
229-
.def(py::init(
230-
[](size_t size, uint16_t default_value) {
231-
return sdsl::int_vector<16>(size, default_value, 16); }),
232-
py::arg("size") = 0, py::arg("default_value") = 0),
233229

234-
add_int_class<sdsl::int_vector<24>, uint32_t>(
235-
m, int_vectors_dict, 24, "Int24Vector")
236-
.def(py::init(
237-
[](size_t size, uint32_t default_value) {
238-
return sdsl::int_vector<24>(size, default_value, 24); }),
239-
py::arg("size") = 0, py::arg("default_value") = 0),
230+
inline auto add_int_vectors(py::module& m)
231+
{
232+
py::dict int_vectors_dict;
240233

241-
add_int_class<sdsl::int_vector<32>, uint32_t>(
242-
m, int_vectors_dict, 32, "Int32Vector")
243-
.def(py::init(
244-
[](size_t size, uint32_t default_value) {
245-
return sdsl::int_vector<32>(size, default_value, 32); }),
246-
py::arg("size") = 0, py::arg("default_value") = 0),
234+
m.attr("int_vector") = int_vectors_dict;
247235

248-
add_int_class<sdsl::int_vector<64>, uint64_t>(
249-
m, int_vectors_dict, 64, "Int64Vector")
250-
.def(py::init(
251-
[](size_t size, uint64_t default_value) {
252-
return sdsl::int_vector<64>(size, default_value, 64); }),
253-
py::arg("size") = 0, py::arg("default_value") = 0)
254-
);
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+
// );
255256

256257
}

0 commit comments

Comments
 (0)