Skip to content

Commit 978efd3

Browse files
committed
define code generation
1 parent 9cef81a commit 978efd3

File tree

2 files changed

+18
-43
lines changed

2 files changed

+18
-43
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: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -208,49 +208,17 @@ inline auto add_int_vectors(py::module& m)
208208
py::arg("size") = 0, py::arg("default_value") = false)
209209
.def("flip", &sdsl::int_vector<1>::flip,
210210
"Flip all bits of bit_vector",
211-
py::call_guard<py::gil_scoped_release>()),
212-
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),
219-
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),
226-
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),
233-
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),
240-
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),
247-
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)
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
254222
);
255223

256224
}

0 commit comments

Comments
 (0)