23 LeafForwardIterator _lf_iterator;
26 CONTAINER_ITERATOR container_iterator;
27 bool container_iterator_end_flag =
true;
31 using iterator_category = std::bidirectional_iterator_tag;
32 using difference_type = std::ptrdiff_t;
40 this->tree =
const_cast<Tree *
>(_tree);
43 _root->copy_to(this->_lf_iterator);
45 if (this->_lf_iterator.is_end())
47 this->container_iterator_end_flag =
true;
51 uint64_t leaf_index = *this->_lf_iterator;
53 this->container_iterator_end_flag =
false;
54 this->container_iterator = container.begin();
60 this->_lf_iterator.idx = UINT64_MAX;
72 return this->_lf_iterator.is_end() && this->container_iterator_end_flag;
77 if (this->_lf_iterator.idx != other._lf_iterator.idx)
79 if (this->_lf_iterator.idx < other._lf_iterator.idx)
90 if (this->container_iterator != other.container_iterator)
92 if (this->container_iterator < other.container_iterator)
103 bool b1 = this->container_iterator_end_flag;
104 bool b2 = other.container_iterator_end_flag;
124 uint64_t operator*()
const
131 int64_t current_bits = 0;
132 int64_t current_bit_size = 0;
137 throw std::invalid_argument(
"Error: BitForwardIterator::operator++()");
141 if (this->_lf_iterator.is_end() && !this->container_iterator_end_flag)
143 this->container_iterator_end_flag =
true;
149 while (current_bit_size < 64 && !this->is_end())
151 if (!this->container_iterator_end_flag)
154 uint64_t xbits_size = std::min((uint64_t)this->container_iterator.get_size() - this->container_iterator.index, 64ULL);
156 uint64_t xbits = (this->container_iterator.read_64bits_string() >> (64 - xbits_size)) << (64 - xbits_size);
157 assert(xbits_size >=1);
159 assert(xbits_size <= 64);
160 current_bits = current_bits | (xbits >> current_bit_size);
162 if (current_bit_size + xbits_size >= 64)
164 uint64_t read_bit_size = 64 - current_bit_size;
165 this->container_iterator += read_bit_size;
166 current_bit_size += read_bit_size;
170 this->container_iterator += xbits_size;
171 current_bit_size += xbits_size;
174 if (this->container_iterator.is_end())
176 this->container_iterator_end_flag =
true;
179 else if (!this->_lf_iterator.is_end())
182 ++this->_lf_iterator;
184 this->container_iterator_end_flag =
false;
185 if (!this->_lf_iterator.is_end())
187 uint64_t leaf_index = *this->_lf_iterator;
189 this->container_iterator = container.begin();
200 throw std::invalid_argument(
"Error: BitForwardIterator::operator++()");
203 this->bits = current_bits;
207 bool operator==(
const BitForwardIterator &other)
const {
return this->compare(other) == 0; }
208 bool operator!=(
const BitForwardIterator &other)
const {
return this->compare(other) != 0; }
209 bool operator<(
const BitForwardIterator &other)
const {
return this->compare(other) < 0; }
210 bool operator>(
const BitForwardIterator &other)
const {
return this->compare(other) > 0; }
211 bool operator<=(
const BitForwardIterator &other)
const {
return this->compare(other) <= 0; }
212 bool operator>=(
const BitForwardIterator &other)
const {
return this->compare(other) >= 0; }