Just another Perl shrine | |
PerlMonks |
Re^10: Bit vector fiddling with Inline Cby BrowserUk (Patriarch) |
on May 11, 2011 at 01:01 UTC ( [id://904058]=note: print w/replies, xml ) | Need Help?? |
in accordance with the op's description of finding "every set bit in vector A, then set the corresponding bit(s) in vector B". Okay. I missed that. Makes sense now. A smarter approach would be to do B = A|B, or in gmp parlance mpz_ior(B, A, B); 'cept that the OP also said that the two vectors aren't in the same order (or even size) and the mapping isn't one to one. But rather, driven by pairs of numbers, a better description might be if( vecA[ 123 ] ) then vecB[ 456 ] = vecB[ 012 ] = 1; I'd want to see benchmarks done before ruling out gmp. Me too. Though I don't think the size of the vectors will affect the results. Something like:
will handle vectors up to 2 Exabytes with linear efficiency--assuming you had enough memory to hold it :) Mind you, if I was going to be processing a list of pairs, then I'd move the acquisition of the vector addresses & lengths out of the loop and use macros for the bit testing and setting:
In theory at least, the compiler is more likely to be able to optimise common sub-expression if they do not cross function boundaries. Even in-lined function boundaries. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom
|
|