MCPcopy Create free account
hub / github.com/apache/arrow / PutOffsets

Function PutOffsets

cpp/src/arrow/array/concatenate.cc:179–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177
178template <typename Offset>
179Result<OffsetBufferOpOutcome> PutOffsets(const Buffer& src, Offset first_offset,
180 Offset* dst, Range* values_range) {
181 if (src.size() == 0) {
182 // It's allowed to have an empty offsets buffer for a 0-length array
183 // (see Array::Validate)
184 values_range->offset = 0;
185 values_range->length = 0;
186 return OffsetBufferOpOutcome::kOk;
187 }
188
189 // Get the range of offsets to transfer from src
190 auto src_begin = src.data_as<Offset>();
191 auto src_end = reinterpret_cast<const Offset*>(src.data() + src.size());
192
193 // Compute the range of values which is spanned by this range of offsets
194 values_range->offset = src_begin[0];
195 values_range->length = *src_end - values_range->offset;
196 if (ARROW_PREDICT_FALSE(first_offset >
197 std::numeric_limits<Offset>::max() - values_range->length)) {
198 return OffsetBufferOpOutcome::kOffsetOverflow;
199 }
200
201 // Write offsets into dst, ensuring that the first offset written is
202 // first_offset
203 auto displacement = first_offset - src_begin[0];
204 // NOTE: Concatenate can be called during IPC reads to append delta dictionaries.
205 // Avoid UB on non-validated input by doing the addition in the unsigned domain.
206 // (the result can later be validated using Array::ValidateFull)
207 std::transform(src_begin, src_end, dst, [displacement](Offset offset) {
208 return SafeSignedAdd(offset, displacement);
209 });
210 return OffsetBufferOpOutcome::kOk;
211}
212
213template <typename offset_type>
214Result<OffsetBufferOpOutcome> PutListViewOffsets(const ArrayData& input,

Callers

nothing calls this directly

Calls 3

SafeSignedAddFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected