felipecrv commented on code in PR #35345: URL: https://github.com/apache/arrow/pull/35345#discussion_r1337927105
########## cpp/src/arrow/util/list_util.cc: ########## @@ -0,0 +1,285 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include <cstdint> +#include <vector> + +#include "arrow/array/array_nested.h" +#include "arrow/array/builder_nested.h" +#include "arrow/array/data.h" +#include "arrow/type.h" +#include "arrow/type_traits.h" +#include "arrow/util/bit_run_reader.h" +#include "arrow/util/checked_cast.h" +#include "arrow/util/list_util.h" +#include "arrow/util/logging.h" +#include "arrow/util/string.h" + +namespace arrow::list_util { + +namespace internal { + +namespace { + +using arrow::internal::checked_cast; + +/// \pre input.length() > 0 && input.null_count() != input.length() +/// \param input A LIST_VIEW or LARGE_LIST_VIEW array +template <typename offset_type> +int64_t MinViewOffset(const ArraySpan& input) { + const uint8_t* validity = input.MayHaveNulls() ? input.buffers[0].data : nullptr; + const auto* offsets = reinterpret_cast<const offset_type*>(input.buffers[1].data); + const auto* sizes = reinterpret_cast<const offset_type*>(input.buffers[2].data); + + // It's very likely that the first non-null non-empty list-view starts at + // offset 0 of the child array. + int64_t i = 0; + while (i < input.length && (input.IsNull(i) || sizes[input.offset + i] == 0)) { + i += 1; + } + if (i >= input.length) { + return 0; + } + auto min_offset = offsets[input.offset + i]; + if (ARROW_PREDICT_TRUE(min_offset == 0)) { + // Early exit: offset 0 found already. + return 0; + } Review Comment: I will rewrite this, but I only want to compare against 0 in the loop body if `offsets[i] < min_offset`, hence the need to compare `min_offset` against 0 before entering the loop. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
