Re: Efficently scanning a bit array

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

 



On Tue, Jul 1, 2008 at 3:40 AM, Chris Jefferson <chris@xxxxxxxxxxxxxxx> wrote:
> I want to implement the following function efficently:
>
> void check_bits(char* ptr, int length)
> {
>  for each bit in the array starting at ptr, of length 'length' which is true
>     f(position of bit);
> }
>
> Where the position of bit is it's position compared to the start of
> the array (so the first bit of *(ptr+2) is at position 16, assuming 8
> bits per byte!)

Why not first check the longest size that makes sense to see if any
bits are set at all if things are really sparse -- if (*(long *)
ptr))... and then check the bits if it is true, but perhaps
__builtin_ffs is just as fast.

-- 
Andrew Bell
andrew.bell.ia@xxxxxxxxx

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux