\brief Return the next run of available bits, usually 256. The returned pair contains the size of run and the number of true values. The last block will have a length less than 256 if the bitmap length is not a multiple of 256, and will return 0-length blocks in subsequent invocations.
| 120 | /// multiple of 256, and will return 0-length blocks in subsequent |
| 121 | /// invocations. |
| 122 | BitBlockCount NextFourWords() { |
| 123 | using detail::LoadWord; |
| 124 | using detail::ShiftWord; |
| 125 | |
| 126 | if (!bits_remaining_) { |
| 127 | return {0, 0}; |
| 128 | } |
| 129 | int64_t total_popcount = 0; |
| 130 | if (offset_ == 0) { |
| 131 | if (bits_remaining_ < kFourWordsBits) { |
| 132 | return GetBlockSlow(kFourWordsBits); |
| 133 | } |
| 134 | total_popcount += std::popcount(LoadWord(bitmap_)); |
| 135 | total_popcount += std::popcount(LoadWord(bitmap_ + 8)); |
| 136 | total_popcount += std::popcount(LoadWord(bitmap_ + 16)); |
| 137 | total_popcount += std::popcount(LoadWord(bitmap_ + 24)); |
| 138 | } else { |
| 139 | // When the offset is > 0, we need there to be a word beyond the last |
| 140 | // aligned word in the bitmap for the bit shifting logic. |
| 141 | if (bits_remaining_ < 5 * kFourWordsBits - offset_) { |
| 142 | return GetBlockSlow(kFourWordsBits); |
| 143 | } |
| 144 | auto current = LoadWord(bitmap_); |
| 145 | auto next = LoadWord(bitmap_ + 8); |
| 146 | total_popcount += std::popcount(ShiftWord(current, next, offset_)); |
| 147 | current = next; |
| 148 | next = LoadWord(bitmap_ + 16); |
| 149 | total_popcount += std::popcount(ShiftWord(current, next, offset_)); |
| 150 | current = next; |
| 151 | next = LoadWord(bitmap_ + 24); |
| 152 | total_popcount += std::popcount(ShiftWord(current, next, offset_)); |
| 153 | current = next; |
| 154 | next = LoadWord(bitmap_ + 32); |
| 155 | total_popcount += std::popcount(ShiftWord(current, next, offset_)); |
| 156 | } |
| 157 | bitmap_ += bit_util::BytesForBits(kFourWordsBits); |
| 158 | bits_remaining_ -= kFourWordsBits; |
| 159 | return {256, static_cast<int16_t>(total_popcount)}; |
| 160 | } |
| 161 | |
| 162 | /// \brief Return the next run of available bits, usually 64. The returned |
| 163 | /// pair contains the size of run and the number of true values. The last |
nothing calls this directly
no test coverage detected