I started trying the Python part of Boost C++ libraries recently and found it surprisingly easy to use. In search of a mini-project, I started coding a Python extension module to expose the Boost dynamic bitset for use in Python. It started as a novelty for a quick talk at the DFW Python group but I got stumped by adding operators.. until last night.
Here's a recap:
The constructor can accept a string ('111000') or a number of bits or a number of bits and an initial value. You can have a very large number of bits - in the millions without a problem.
The logical operators (&|^) work as expected and even throw polite exceptions when the operands are of different sizes.
There is a count method to see how many bits are on, a test method that returns true if the bit at a given index is on, a flip (or toggle) method..
There are even docstrings!
Available at:
https://python.taupro.com/repo/Projects/boost_python
It may be interesting to build pure python version and then use both to implement Conway's Game of Life to see what the difference in speed is.
No comments:
Post a Comment