Thread overview | |||||
---|---|---|---|---|---|
|
March 01, 2016 BitArray: count the number of bits set | ||||
---|---|---|---|---|
| ||||
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. |
March 01, 2016 Re: BitArray: count the number of bits set | ||||
---|---|---|---|---|
| ||||
Posted in reply to yawniek | 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" :)
|
March 01, 2016 Re: BitArray: count the number of bits set | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Tuesday, 1 March 2016 at 09:32:20 UTC, Andrea Fontana wrote: > Maybe you should look for "hamming weight" :) maybe. and here is a snowman for you: ☃ the question was if it exists for BitArray in phobos. https://issues.dlang.org/show_bug.cgi?id=10239 so apparently its really missing in phobos BitArray. the algo is even described in TDPL. |
Copyright © 1999-2021 by the D Language Foundation