BitArray: count the number of bits set

Andrea Fontana via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 1 01:32:20 PST 2016


On Tuesday, 1 March 2016 at 09:03:47 UTC, yawniek wrote:
> i figured i can count the number of bits set for a BitArray 
> with std.algorithm : count:
>
> BitArray([0,0,1]).bitsSet.count()
>
> but this seems not very optimal, is there a faster way directly 
> accessible trough phobos?
>
> ideally something that is optimized by the compiler.

Maybe you should look for "hamming weight" :)


More information about the Digitalmars-d-learn mailing list