Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:27:09

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include <cstdint>
0021 #include <type_traits>
0022 
0023 #include "arrow/status.h"
0024 
0025 #include "arrow/util/visibility.h"
0026 
0027 namespace arrow {
0028 
0029 class DataType;
0030 struct ArraySpan;
0031 struct Scalar;
0032 
0033 namespace internal {
0034 
0035 ARROW_EXPORT
0036 uint8_t DetectUIntWidth(const uint64_t* values, int64_t length, uint8_t min_width = 1);
0037 
0038 ARROW_EXPORT
0039 uint8_t DetectUIntWidth(const uint64_t* values, const uint8_t* valid_bytes,
0040                         int64_t length, uint8_t min_width = 1);
0041 
0042 ARROW_EXPORT
0043 uint8_t DetectIntWidth(const int64_t* values, int64_t length, uint8_t min_width = 1);
0044 
0045 ARROW_EXPORT
0046 uint8_t DetectIntWidth(const int64_t* values, const uint8_t* valid_bytes, int64_t length,
0047                        uint8_t min_width = 1);
0048 
0049 ARROW_EXPORT
0050 void DowncastInts(const int64_t* source, int8_t* dest, int64_t length);
0051 
0052 ARROW_EXPORT
0053 void DowncastInts(const int64_t* source, int16_t* dest, int64_t length);
0054 
0055 ARROW_EXPORT
0056 void DowncastInts(const int64_t* source, int32_t* dest, int64_t length);
0057 
0058 ARROW_EXPORT
0059 void DowncastInts(const int64_t* source, int64_t* dest, int64_t length);
0060 
0061 ARROW_EXPORT
0062 void DowncastUInts(const uint64_t* source, uint8_t* dest, int64_t length);
0063 
0064 ARROW_EXPORT
0065 void DowncastUInts(const uint64_t* source, uint16_t* dest, int64_t length);
0066 
0067 ARROW_EXPORT
0068 void DowncastUInts(const uint64_t* source, uint32_t* dest, int64_t length);
0069 
0070 ARROW_EXPORT
0071 void DowncastUInts(const uint64_t* source, uint64_t* dest, int64_t length);
0072 
0073 ARROW_EXPORT
0074 void UpcastInts(const int32_t* source, int64_t* dest, int64_t length);
0075 
0076 template <typename InputInt, typename OutputInt>
0077 inline typename std::enable_if<(sizeof(InputInt) >= sizeof(OutputInt))>::type CastInts(
0078     const InputInt* source, OutputInt* dest, int64_t length) {
0079   DowncastInts(source, dest, length);
0080 }
0081 
0082 template <typename InputInt, typename OutputInt>
0083 inline typename std::enable_if<(sizeof(InputInt) < sizeof(OutputInt))>::type CastInts(
0084     const InputInt* source, OutputInt* dest, int64_t length) {
0085   UpcastInts(source, dest, length);
0086 }
0087 
0088 template <typename InputInt, typename OutputInt>
0089 ARROW_EXPORT void TransposeInts(const InputInt* source, OutputInt* dest, int64_t length,
0090                                 const int32_t* transpose_map);
0091 
0092 ARROW_EXPORT
0093 Status TransposeInts(const DataType& src_type, const DataType& dest_type,
0094                      const uint8_t* src, uint8_t* dest, int64_t src_offset,
0095                      int64_t dest_offset, int64_t length, const int32_t* transpose_map);
0096 
0097 /// \brief Do vectorized boundschecking of integer-type array indices. The
0098 /// indices must be nonnegative and strictly less than the passed upper
0099 /// limit (which is usually the length of an array that is being indexed-into).
0100 ARROW_EXPORT
0101 Status CheckIndexBounds(const ArraySpan& values, uint64_t upper_limit);
0102 
0103 /// \brief Boundscheck integer values to determine if they are all between the
0104 /// passed upper and lower limits (inclusive). Upper and lower bounds must be
0105 /// the same type as the data and are not currently casted.
0106 ARROW_EXPORT
0107 Status CheckIntegersInRange(const ArraySpan& values, const Scalar& bound_lower,
0108                             const Scalar& bound_upper);
0109 
0110 /// \brief Use CheckIntegersInRange to determine whether the passed integers
0111 /// can fit safely in the passed integer type. This helps quickly determine if
0112 /// integer narrowing (e.g. int64->int32) is safe to do.
0113 ARROW_EXPORT
0114 Status IntegersCanFit(const ArraySpan& values, const DataType& target_type);
0115 
0116 /// \brief Convenience for boundschecking a single Scalar value
0117 ARROW_EXPORT
0118 Status IntegersCanFit(const Scalar& value, const DataType& target_type);
0119 
0120 /// Upcast an integer to the largest possible width (currently 64 bits)
0121 
0122 template <typename Integer>
0123 typename std::enable_if<
0124     std::is_integral<Integer>::value && std::is_signed<Integer>::value, int64_t>::type
0125 UpcastInt(Integer v) {
0126   return v;
0127 }
0128 
0129 template <typename Integer>
0130 typename std::enable_if<
0131     std::is_integral<Integer>::value && std::is_unsigned<Integer>::value, uint64_t>::type
0132 UpcastInt(Integer v) {
0133   return v;
0134 }
0135 
0136 }  // namespace internal
0137 }  // namespace arrow