| 613 | |
| 614 | // Iterator support for efficient traversal of set bits |
| 615 | class set_bit_iterator |
| 616 | { |
| 617 | public: |
| 618 | using iterator_category = std::bidirectional_iterator_tag; |
| 619 | using value_type = int64_t; |
| 620 | using difference_type = int64_t; |
| 621 | using pointer = int64_t*; |
| 622 | using reference = int64_t&; |
| 623 | |
| 624 | private: |
| 625 | const bit_vector* bv_; |
| 626 | int64_t current_position_; |
| 627 | |
| 628 | public: |
| 629 | set_bit_iterator(const bit_vector* bv, bool at_end = false) |
| 630 | : bv_(bv) |
| 631 | { |
| 632 | if (at_end) { |
| 633 | current_position_ = bv_->size(); |
| 634 | } else { |
| 635 | current_position_ = bv_->find_first_set(); |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | int64_t operator*() const |
| 640 | { |
| 641 | ASSERT(current_position_ >= 0); |
| 642 | return static_cast<int64_t>(current_position_); |
| 643 | } |
| 644 | |
| 645 | set_bit_iterator& operator++() |
| 646 | { |
| 647 | if (current_position_ >= 0) { |
| 648 | current_position_ = bv_->find_next_set(static_cast<int64_t>(current_position_)); |
| 649 | } |
| 650 | return *this; |
| 651 | } |
| 652 | |
| 653 | set_bit_iterator operator++(int) |
| 654 | { |
| 655 | set_bit_iterator tmp = *this; |
| 656 | ++*this; |
| 657 | return tmp; |
| 658 | } |
| 659 | |
| 660 | set_bit_iterator& operator--() |
| 661 | { |
| 662 | if (current_position_ >= 0) { |
| 663 | current_position_ = bv_->find_prev_set(static_cast<int64_t>(current_position_)); |
| 664 | } |
| 665 | return *this; |
| 666 | } |
| 667 | |
| 668 | set_bit_iterator operator--(int) |
| 669 | { |
| 670 | set_bit_iterator tmp = *this; |
| 671 | --*this; |
| 672 | return tmp; |
no test coverage detected