lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hans van der Meer wrote:

Yes, it is an array of bits, packed as tight as can be. Bits in the array can be set, queried and iterated on. The testfile in the package does a prime number sieve of Eratosthenes as an example, showing that very many boolean flags can be manipulated comfortably.

Indeed, metamethods may be used for combining bitmaps with AND, OR, XOR.

The module cannot do arithmetic operations(like i<<1 or i>>1 for doing powers of two). It was not designed as such and I agree with the quote of Roberto in that one should not lightly tamper with arithmetics.

Hans van der Meer

In all respect, I beg to differ. Quite a few algorithms could be significantly improved/facilitated/made implementable with such direct bitwise ops, though I agree that adding << and >> just for performing powers of two is indeed a waste, but I'd only used those as an example. Your implementation seems to handle bitflags well, which is the main reason (for me at least, that + some algorithms) I'm hoping for bitwise ops. But I'd think it'd be more overhead/bother to do (sorry don't have the ref sheet with me ATM so please bear as I use the incorrect constructs/method calls):


Instead of:


Adding your object as a core type might be a solution, but then that adds a kludge to Lua's otherwise (near-?)perfect type universe.