pitrou commented on code in PR #13009:
URL: https://github.com/apache/arrow/pull/13009#discussion_r865038679


##########
cpp/src/arrow/stl_iterator.h:
##########
@@ -128,6 +132,153 @@ class ArrayIterator {
   int64_t index_;
 };
 
+template <typename ArrayType,
+          typename ValueAccessor = detail::DefaultValueAccessor<ArrayType>>
+class ChunkedArrayIterator {
+ public:
+  using value_type = arrow::util::optional<typename ValueAccessor::ValueType>;
+  using difference_type = int64_t;
+  using pointer = value_type*;
+  using reference = value_type&;
+  using iterator_category = std::random_access_iterator_tag;
+
+  // Some algorithms need to default-construct an iterator
+  ChunkedArrayIterator() : chunked_array_(NULLPTR), index_(0), 
current_chunk_index_(0) {}
+
+  explicit ChunkedArrayIterator(const ChunkedArray& chunked_array, int64_t 
index = 0)
+      : chunked_array_(&chunked_array), index_(index) {
+    auto chunk_location = GetChunkLocation(this->index_);
+    if (chunked_array.length()) {
+      current_array_iterator_ = ArrayIterator<ArrayType>(
+          *arrow::internal::checked_pointer_cast<ArrayType>(
+              
chunked_array_->chunk(static_cast<int>(chunk_location.chunk_index))),
+          index_);
+    } else {
+      current_array_iterator_ = {};
+    }
+
+    this->current_chunk_index_ = chunk_location.chunk_index;
+    current_array_iterator_ -= this->index() - chunk_location.index_in_chunk;
+  }
+
+  // Value access
+  value_type operator*() const { return *current_array_iterator_; }
+
+  value_type operator[](difference_type n) const {
+    auto chunk_location = GetChunkLocation(index_ + n);
+    if (current_chunk_index_ == chunk_location.chunk_index) {

Review Comment:
   Well, first you should use `checked_cast` as there's no reason to create a 
new `shared_ptr`. Second, in release mode `checked_cast` is a static cast that 
doesn't have any actual cost.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to