Lost Interrupt
just random carefree notes
Wednesday, January 26, 2011
loop over one-bits of an integer
If you need to have a loop iterated as many times as there are 1-bits in an integer
v
it is better to write
for (;v;v &= v-1)
than
for (i = popcnt(v); i>0; i--)
because the former has O(popcnt(v)) compexity against the latter's O(width(v)).
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment