| 402 | } |
| 403 | |
| 404 | SetBitRun FindCurrentRun() { |
| 405 | // Skip any pending zeros |
| 406 | const auto num_zeros = CountFirstZeros(current_word_); |
| 407 | if (num_zeros >= current_num_bits_) { |
| 408 | remaining_ -= current_num_bits_; |
| 409 | current_word_ = 0; |
| 410 | current_num_bits_ = 0; |
| 411 | return {0, 0}; |
| 412 | } |
| 413 | assert(num_zeros <= remaining_); |
| 414 | current_word_ = ConsumeBits(current_word_, num_zeros); |
| 415 | current_num_bits_ -= num_zeros; |
| 416 | remaining_ -= num_zeros; |
| 417 | const int64_t pos = position(); |
| 418 | // Count any ones |
| 419 | const auto num_ones = CountFirstZeros(~current_word_); |
| 420 | assert(num_ones <= current_num_bits_); |
| 421 | assert(num_ones <= remaining_); |
| 422 | current_word_ = ConsumeBits(current_word_, num_ones); |
| 423 | current_num_bits_ -= num_ones; |
| 424 | remaining_ -= num_ones; |
| 425 | return {pos, num_ones}; |
| 426 | } |
| 427 | |
| 428 | inline int CountFirstZeros(uint64_t word); |
| 429 | inline uint64_t ConsumeBits(uint64_t word, int32_t num_bits); |