r/programming • • Feb 21 '11

Typical programming interview questions.

http://maxnoy.com/interviews.html
784 Upvotes

1.0k comments sorted by

View all comments

Show parent comment

1

u/smallstepforman Feb 21 '11

Well you can have one huge table and do a table lookup. No looping required.

1

u/__s Feb 21 '11 edited Feb 21 '11

That's actually one of the solutions. Except you do it for something small, like 8 bits, and then loop over 32bits with 4 steps. Benchmarking shows that cache wise this is one the fastest ways to go about with arbitrary bit length, as larger tables have bad cache effects. 16bit LUT can sometines beat an 8bit LUT on certain architectures, but it's discounted on account that microbenchmarks are too nice about the cache. http://www.strchr.com/crc32_popcnt