2012-09-09

Population count

先日の「Long.bitCount(long) の速度」の記事で比較した it.unimi.dsi.bits.Fast.count(long) だが、Wikipedia にも同様のコードが載っていてショック。
Hamming weight - Wikipedia, the free encyclopedia
http://en.wikipedia.org/wiki/Hamming_weight
そのコードを一般化したものが次のページに載っている。
Counting bits set, in parallel - Bit Twiddling Hacks
http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel