>> Given a value 2 ^ k, does anyone know how to efficiently extract k
>> (other than a shift loop?)
>
>Use a hash table.  n % 19 has no collisions on { 2^k: 0 <= k < 16 },
>and n % 37 similarly for 0 <= k < 32.

I wonder if that's just efficient source code, instead of fast object code.
Doing a shift loop can't be that bad, and if you "cheat" by testing the low
8 or 16 bits to see if they're zero first, well, we're probably fast enough
to not care any more.

I always love O(1) algorithms but they're not necessarily the fastest!

-David Fedor
Palm Developer Support

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to