| 298 | namespace internal { |
| 299 | |
| 300 | bool MultipleChunkIterator::Next(std::shared_ptr<Array>* next_left, |
| 301 | std::shared_ptr<Array>* next_right) { |
| 302 | if (pos_ == length_) return false; |
| 303 | |
| 304 | // Find non-empty chunk |
| 305 | std::shared_ptr<Array> chunk_left, chunk_right; |
| 306 | while (true) { |
| 307 | chunk_left = left_.chunk(chunk_idx_left_); |
| 308 | chunk_right = right_.chunk(chunk_idx_right_); |
| 309 | if (chunk_pos_left_ == chunk_left->length()) { |
| 310 | chunk_pos_left_ = 0; |
| 311 | ++chunk_idx_left_; |
| 312 | continue; |
| 313 | } |
| 314 | if (chunk_pos_right_ == chunk_right->length()) { |
| 315 | chunk_pos_right_ = 0; |
| 316 | ++chunk_idx_right_; |
| 317 | continue; |
| 318 | } |
| 319 | break; |
| 320 | } |
| 321 | // Determine how big of a section to return |
| 322 | int64_t iteration_size = std::min(chunk_left->length() - chunk_pos_left_, |
| 323 | chunk_right->length() - chunk_pos_right_); |
| 324 | |
| 325 | *next_left = chunk_left->Slice(chunk_pos_left_, iteration_size); |
| 326 | *next_right = chunk_right->Slice(chunk_pos_right_, iteration_size); |
| 327 | |
| 328 | pos_ += iteration_size; |
| 329 | chunk_pos_left_ += iteration_size; |
| 330 | chunk_pos_right_ += iteration_size; |
| 331 | return true; |
| 332 | } |
| 333 | |
| 334 | } // namespace internal |
| 335 | } // namespace arrow |