Clever large integersWhere bitmap = bitmap & ~(1L << bit) This is the perfectly normal way of clearing a bit in a bitmap, so it looks like there's nothing peculiar going on here. Except that Python longs are of indefinite (and theoretically infinite)
length, and what makes this expression work in normal integers is that
the two pieces have the same (finite) size. So Python is clearly not
just doing straight binary operations here; the implementation of All of this goes to illustrate that sometimes features aren't as simple as they look. As it turns out, this cleverness has a cost, at least in Python. If
you already know that the bit is set, clearing it with (Checking plus subtraction is usually slower than the AND approach alone; it gets slightly faster when we start operating around bit 2048 and up. Of course, large bits is exactly where you probably want a faster representation of your bitmaps than a large integer, which should speed everything up.) (2 comments.)
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |