File indexing completed on 2025-08-28 08:27:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
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
0098
0099
0100 ARROW_EXPORT
0101 Status CheckIndexBounds(const ArraySpan& values, uint64_t upper_limit);
0102
0103
0104
0105
0106 ARROW_EXPORT
0107 Status CheckIntegersInRange(const ArraySpan& values, const Scalar& bound_lower,
0108 const Scalar& bound_upper);
0109
0110
0111
0112
0113 ARROW_EXPORT
0114 Status IntegersCanFit(const ArraySpan& values, const DataType& target_type);
0115
0116
0117 ARROW_EXPORT
0118 Status IntegersCanFit(const Scalar& value, const DataType& target_type);
0119
0120
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 }
0137 }