Line segments, overlap, and bits

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Mar 26 18:10:52 EDT 2008


Sean Davis>Java has a BitSet class that keeps this kind of thing
pretty clean and high-level, but I haven't seen anything like it for
python.<

If you look around you can usually find Python code able to do most of
the things you want, like (you can modify this code to add the boolean
operations):
http://svn.zope.org/*checkout*/Zope3/trunk/src/zope/textindex/ricecode.py?content-type=text%2Fplain&rev=8532
(Later I have improved that code for personal use).

But operations on such bit arrays are very common, and you may need
them to be very fast, so you may use Cython (Pyrex) to write a small
class able to do those things in a much faster way.
Or you can also use Pyd plus an easy 30-lines long D program to write
a class that does those operations very quickly  (using a dynamic
array of uint, with the help of www.digitalmars.com/d/1.0/phobos/std_intrinsic.html
).
Maybe you can use GMPY numbers as bit arrays too. (I don't know if you
can use NumPy for this using a compact representation of the bits).

Bye,
bearophile



More information about the Python-list mailing list