A fast bit-counting algorithm

Various information retrieval problems encounter time-consuming bit-counting operations. For example, to choose a rational access strategy it is necessary to repeatedly evaluate the cardinalities of retrieved sets of information items. A straightforward implementation of this procedure involves shifting of data words which makes the time of bit-counting proportional to the length of the machine word. In the suggested implementation, bit-counting is done with machine words as a whole by emulating the summation through some bitwise logical operations. It turns out, that for 32 bits this algorithm runs more than 3 times faster than conventional horizontal methods and is comparable to all other methods for typical random number cases. It is better than all methods in the worst case. In future computers, with 64-bit words and bigger the gain in speed will be correspondingly higher.