The population count function is used in many different scenarios. I first found out about it in the implementation of a HAMT data structure (Hash Array Mapped Trie).
The implementations herein are converted to Ruby from the C functions in this article. MRI is generally faster at these implementations than JRuby, but JRuby shines when any of these functions are called frequently enough to be able to inline the functions.
OS | Yosemite 10.10.4 |
Machine | MacBook Pro (13-inch, Late 2011) |
Processor | 2.4 GHz Intel Core i5 |
Memory | 16 GB 1333 MHz DDR3 |