()
| 92 | } |
| 93 | |
| 94 | func (b Bits) TrueCount() uint32 { |
| 95 | if b.IsZero() { |
| 96 | return 0 |
| 97 | } |
| 98 | var n uint32 |
| 99 | for _, bs := range b.bits { |
| 100 | n += uint32(bits.OnesCount64(bs)) |
| 101 | } |
| 102 | if numTailBits := b.Len() % 64; numTailBits > 0 { |
| 103 | mask := ^uint64(0) << numTailBits |
| 104 | unusedBits := b.bits[len(b.bits)-1] & mask |
| 105 | n -= uint32(bits.OnesCount64(unusedBits)) |
| 106 | } |
| 107 | return n |
| 108 | } |
| 109 | |
| 110 | // helpful to have around for debugging |
| 111 | func (b Bits) String() string { |