![]() |
|
|||
File indexing completed on 2025-08-28 08:27:03
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 <memory> 0022 0023 #include "arrow/result.h" 0024 #include "arrow/util/visibility.h" 0025 0026 namespace arrow { 0027 0028 class Buffer; 0029 class MemoryPool; 0030 0031 namespace internal { 0032 0033 // ---------------------------------------------------------------------- 0034 // Bitmap utilities 0035 0036 /// Copy a bit range of an existing bitmap 0037 /// 0038 /// \param[in] pool memory pool to allocate memory from 0039 /// \param[in] bitmap source data 0040 /// \param[in] offset bit offset into the source data 0041 /// \param[in] length number of bits to copy 0042 /// 0043 /// \return Status message 0044 ARROW_EXPORT 0045 Result<std::shared_ptr<Buffer>> CopyBitmap(MemoryPool* pool, const uint8_t* bitmap, 0046 int64_t offset, int64_t length); 0047 0048 /// Copy a bit range of an existing bitmap into an existing bitmap 0049 /// 0050 /// \param[in] bitmap source data 0051 /// \param[in] offset bit offset into the source data 0052 /// \param[in] length number of bits to copy 0053 /// \param[in] dest_offset bit offset into the destination 0054 /// \param[out] dest the destination buffer, must have at least space for 0055 /// (offset + length) bits 0056 ARROW_EXPORT 0057 void CopyBitmap(const uint8_t* bitmap, int64_t offset, int64_t length, uint8_t* dest, 0058 int64_t dest_offset); 0059 0060 /// Invert a bit range of an existing bitmap into an existing bitmap 0061 /// 0062 /// \param[in] bitmap source data 0063 /// \param[in] offset bit offset into the source data 0064 /// \param[in] length number of bits to copy 0065 /// \param[in] dest_offset bit offset into the destination 0066 /// \param[out] dest the destination buffer, must have at least space for 0067 /// (offset + length) bits 0068 ARROW_EXPORT 0069 void InvertBitmap(const uint8_t* bitmap, int64_t offset, int64_t length, uint8_t* dest, 0070 int64_t dest_offset); 0071 0072 /// Invert a bit range of an existing bitmap 0073 /// 0074 /// \param[in] pool memory pool to allocate memory from 0075 /// \param[in] bitmap source data 0076 /// \param[in] offset bit offset into the source data 0077 /// \param[in] length number of bits to copy 0078 /// 0079 /// \return Status message 0080 ARROW_EXPORT 0081 Result<std::shared_ptr<Buffer>> InvertBitmap(MemoryPool* pool, const uint8_t* bitmap, 0082 int64_t offset, int64_t length); 0083 0084 /// Reverse a bit range of an existing bitmap into an existing bitmap 0085 /// 0086 /// \param[in] bitmap source data 0087 /// \param[in] offset bit offset into the source data 0088 /// \param[in] length number of bits to reverse 0089 /// \param[in] dest_offset bit offset into the destination 0090 /// \param[out] dest the destination buffer, must have at least space for 0091 /// (offset + length) bits 0092 ARROW_EXPORT 0093 void ReverseBitmap(const uint8_t* bitmap, int64_t offset, int64_t length, uint8_t* dest, 0094 int64_t dest_offset); 0095 0096 /// Reverse a bit range of an existing bitmap 0097 /// 0098 /// \param[in] pool memory pool to allocate memory from 0099 /// \param[in] bitmap source data 0100 /// \param[in] offset bit offset into the source data 0101 /// \param[in] length number of bits to reverse 0102 /// 0103 /// \return Status message 0104 ARROW_EXPORT 0105 Result<std::shared_ptr<Buffer>> ReverseBitmap(MemoryPool* pool, const uint8_t* bitmap, 0106 int64_t offset, int64_t length); 0107 0108 /// Compute the number of 1's in the given data array 0109 /// 0110 /// \param[in] data a packed LSB-ordered bitmap as a byte array 0111 /// \param[in] bit_offset a bitwise offset into the bitmap 0112 /// \param[in] length the number of bits to inspect in the bitmap relative to 0113 /// the offset 0114 /// 0115 /// \return The number of set (1) bits in the range 0116 ARROW_EXPORT 0117 int64_t CountSetBits(const uint8_t* data, int64_t bit_offset, int64_t length); 0118 0119 /// Compute the number of 1's in the result of an "and" (&) of two bitmaps 0120 /// 0121 /// \param[in] left_bitmap a packed LSB-ordered bitmap as a byte array 0122 /// \param[in] left_offset a bitwise offset into the left bitmap 0123 /// \param[in] right_bitmap a packed LSB-ordered bitmap as a byte array 0124 /// \param[in] right_offset a bitwise offset into the right bitmap 0125 /// \param[in] length the length of the bitmaps (must be the same) 0126 /// 0127 /// \return The number of set (1) bits in the "and" of the two bitmaps 0128 ARROW_EXPORT 0129 int64_t CountAndSetBits(const uint8_t* left_bitmap, int64_t left_offset, 0130 const uint8_t* right_bitmap, int64_t right_offset, 0131 int64_t length); 0132 0133 ARROW_EXPORT 0134 bool BitmapEquals(const uint8_t* left, int64_t left_offset, const uint8_t* right, 0135 int64_t right_offset, int64_t length); 0136 0137 // Same as BitmapEquals, but considers a NULL bitmap pointer the same as an 0138 // all-ones bitmap. 0139 ARROW_EXPORT 0140 bool OptionalBitmapEquals(const uint8_t* left, int64_t left_offset, const uint8_t* right, 0141 int64_t right_offset, int64_t length); 0142 0143 ARROW_EXPORT 0144 bool OptionalBitmapEquals(const std::shared_ptr<Buffer>& left, int64_t left_offset, 0145 const std::shared_ptr<Buffer>& right, int64_t right_offset, 0146 int64_t length); 0147 0148 /// \brief Do a "bitmap and" on right and left buffers starting at 0149 /// their respective bit-offsets for the given bit-length and put 0150 /// the results in out_buffer starting at the given bit-offset. 0151 /// 0152 /// out_buffer will be allocated and initialized to zeros using pool before 0153 /// the operation. 0154 ARROW_EXPORT 0155 Result<std::shared_ptr<Buffer>> BitmapAnd(MemoryPool* pool, const uint8_t* left, 0156 int64_t left_offset, const uint8_t* right, 0157 int64_t right_offset, int64_t length, 0158 int64_t out_offset); 0159 0160 /// \brief Do a "bitmap and" on right and left buffers starting at 0161 /// their respective bit-offsets for the given bit-length and put 0162 /// the results in out starting at the given bit-offset. 0163 ARROW_EXPORT 0164 void BitmapAnd(const uint8_t* left, int64_t left_offset, const uint8_t* right, 0165 int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out); 0166 0167 /// \brief Do a "bitmap or" for the given bit length on right and left buffers 0168 /// starting at their respective bit-offsets and put the results in out_buffer 0169 /// starting at the given bit-offset. 0170 /// 0171 /// out_buffer will be allocated and initialized to zeros using pool before 0172 /// the operation. 0173 ARROW_EXPORT 0174 Result<std::shared_ptr<Buffer>> BitmapOr(MemoryPool* pool, const uint8_t* left, 0175 int64_t left_offset, const uint8_t* right, 0176 int64_t right_offset, int64_t length, 0177 int64_t out_offset); 0178 0179 /// \brief Do a "bitmap or" for the given bit length on right and left buffers 0180 /// starting at their respective bit-offsets and put the results in out 0181 /// starting at the given bit-offset. 0182 ARROW_EXPORT 0183 void BitmapOr(const uint8_t* left, int64_t left_offset, const uint8_t* right, 0184 int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out); 0185 0186 /// \brief Do a "bitmap xor" for the given bit-length on right and left 0187 /// buffers starting at their respective bit-offsets and put the results in 0188 /// out_buffer starting at the given bit offset. 0189 /// 0190 /// out_buffer will be allocated and initialized to zeros using pool before 0191 /// the operation. 0192 ARROW_EXPORT 0193 Result<std::shared_ptr<Buffer>> BitmapXor(MemoryPool* pool, const uint8_t* left, 0194 int64_t left_offset, const uint8_t* right, 0195 int64_t right_offset, int64_t length, 0196 int64_t out_offset); 0197 0198 /// \brief Do a "bitmap xor" for the given bit-length on right and left 0199 /// buffers starting at their respective bit-offsets and put the results in 0200 /// out starting at the given bit offset. 0201 ARROW_EXPORT 0202 void BitmapXor(const uint8_t* left, int64_t left_offset, const uint8_t* right, 0203 int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out); 0204 0205 /// \brief Do a "bitmap and not" on right and left buffers starting at 0206 /// their respective bit-offsets for the given bit-length and put 0207 /// the results in out_buffer starting at the given bit-offset. 0208 /// 0209 /// out_buffer will be allocated and initialized to zeros using pool before 0210 /// the operation. 0211 ARROW_EXPORT 0212 Result<std::shared_ptr<Buffer>> BitmapAndNot(MemoryPool* pool, const uint8_t* left, 0213 int64_t left_offset, const uint8_t* right, 0214 int64_t right_offset, int64_t length, 0215 int64_t out_offset); 0216 0217 /// \brief Do a "bitmap and not" on right and left buffers starting at 0218 /// their respective bit-offsets for the given bit-length and put 0219 /// the results in out starting at the given bit-offset. 0220 ARROW_EXPORT 0221 void BitmapAndNot(const uint8_t* left, int64_t left_offset, const uint8_t* right, 0222 int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out); 0223 0224 /// \brief Do a "bitmap or not" on right and left buffers starting at 0225 /// their respective bit-offsets for the given bit-length and put 0226 /// the results in out_buffer starting at the given bit-offset. 0227 /// 0228 /// out_buffer will be allocated and initialized to zeros using pool before 0229 /// the operation. 0230 ARROW_EXPORT 0231 Result<std::shared_ptr<Buffer>> BitmapOrNot(MemoryPool* pool, const uint8_t* left, 0232 int64_t left_offset, const uint8_t* right, 0233 int64_t right_offset, int64_t length, 0234 int64_t out_offset); 0235 0236 /// \brief Do a "bitmap or not" on right and left buffers starting at 0237 /// their respective bit-offsets for the given bit-length and put 0238 /// the results in out starting at the given bit-offset. 0239 ARROW_EXPORT 0240 void BitmapOrNot(const uint8_t* left, int64_t left_offset, const uint8_t* right, 0241 int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out); 0242 0243 } // namespace internal 0244 } // namespace arrow
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |