MCPcopy Create free account
hub / github.com/activeloopai/deeplake / iterator

Class iterator

cpp/nd/impl/stacked_array.hpp:158–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156 }
157
158 class iterator
159 {
160 public:
161 iterator(const vstacked_list_array_base* a, int64_t index, int64_t parent_index)
162 : a_(a)
163 , parent_index_(parent_index)
164 , index_(index)
165 {
166 }
167
168 void operator++()
169 {
170 ++index_;
171 if (index_ >= a_->offsets_[parent_index_] + a_->a_[parent_index_].size()) {
172 ++parent_index_;
173 }
174 }
175
176 void operator--()
177 {
178 --index_;
179 if (index_ < a_->offsets_[parent_index_]) {
180 --parent_index_;
181 }
182 }
183
184 void operator+=(std::ptrdiff_t n)
185 {
186 index_ += n;
187 parent_index_ = std::distance(a_->offsets_.begin(), std::ranges::upper_bound(a_->offsets_, index_)) - 1;
188 }
189
190 void operator-=(std::ptrdiff_t n)
191 {
192 index_ -= n;
193 parent_index_ = std::distance(a_->offsets_.begin(), std::ranges::upper_bound(a_->offsets_, index_)) - 1;
194 }
195
196 std::ptrdiff_t operator-(const iterator& other) const
197 {
198 return index_ - other.index_;
199 }
200
201 bool operator==(const iterator& other) const
202 {
203 return index_ == other.index_;
204 }
205
206 array operator*() const
207 {
208 return a_->a_[parent_index_][index_ - a_->offsets_[parent_index_]];
209 }
210
211 private:
212 const vstacked_list_array_base* a_;
213 int64_t parent_index_;
214 int64_t index_;
215 };

Callers 2

beginMethod · 0.70
endMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected