Returns the number of set bits in the vector.
| 210 | |
| 211 | // Returns the number of set bits in the vector. |
| 212 | int BitVector::NumSetBits() const { |
| 213 | int wordlen = WordLength(); |
| 214 | int total_bits = 0; |
| 215 | for (int w = 0; w < wordlen; ++w) { |
| 216 | uinT32 word = array_[w]; |
| 217 | for (int i = 0; i < 4; ++i) { |
| 218 | total_bits += hamming_table_[word & 0xff]; |
| 219 | word >>= 8; |
| 220 | } |
| 221 | } |
| 222 | return total_bits; |
| 223 | } |
| 224 | |
| 225 | // Logical in-place operations on whole bit vectors. Tries to do something |
| 226 | // sensible if they aren't the same size, but they should be really. |