From dbfd243e5071089c172a8cdbb9b7b412327abcf6 Mon Sep 17 00:00:00 2001 From: Tom Janson Date: Fri, 17 Mar 2017 18:09:24 +0100 Subject: [PATCH] add container API (index access w []) to BitVector --- src/storage/bitvector.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/storage/bitvector.cpp b/src/storage/bitvector.cpp index 03e9d66..130b3dc 100644 --- a/src/storage/bitvector.cpp +++ b/src/storage/bitvector.cpp @@ -17,6 +17,14 @@ void define_bitvector(py::module& m) { //.def("get", &BitVector::get, "index"_a) // no idea why this does not work .def("get", [](BitVector const& b, uint_fast64_t i) { return b.get(i); }, "index"_a) + .def("__len__", [](BitVector const& b) { return b.size(); }) + .def("__getitem__", [](BitVector const& b, uint_fast64_t i) { + if (i >= b.size()) + throw py::index_error(); + return b.get(i); + }) + .def("__setitem__", [](BitVector& b, uint_fast64_t i, bool v) { b.set(i, v); }) + .def(py::self == py::self) .def(py::self != py::self)