in reply to Re: An array of boolean values in a bitfield
in thread An array of boolean values in a bitfield

Where do you get the array @sum? The point of the loop that you're commenting on is specifically to build a lookup table that maps a chr to the number of '1' bits that are in it. That table gets used in some of the bit counting methods that follow.

Replies are listed 'Best First'.
Re^3: An array of boolean values in a bitfield
by LanX (Saint) on Dec 03, 2008 at 18:16 UTC
    I get it, so @sum and %bits_in have the same purpose!

    I'm just confused, why do you care about the speed to calculate a constant table with only 256 entries? And why do you use a hash if speed counts? ... arrays are much faster!

    Cheers Rolf

      I'm not trying to optimize the creation of the lookup table. The lookup table is used to (more quickly) count bits in the bit field. I don't use an array for that because then the lookups would have to call ord to get the index into the array.

        I'm still confused, ... UPDATE: after rereading the code my confusion vanished, (but I'm better leaving the monastry till this starting flue doesn't affect my concentration anymore ;)

        Anyway an extra ord() should be faster than any internal hashfunction. I'm not sure about the usecase, but if you want to tie the functionality, the additional ord() wouldn't bother the user of your module.