1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
1718use crate::ArrayData;
19use arrow_buffer::ArrowNativeType;
20use std::mem::size_of;
21use std::ops::Add;
2223use super::{Extend, _MutableArrayData};
2425pub(super) fn build_extend<T: ArrowNativeType>(array: &ArrayData) -> Extend {
26let values = array.buffer::<T>(0);
27 Box::new(
28move |mutable: &mut _MutableArrayData, _, start: usize, len: usize| {
29 mutable
30 .buffer1
31 .extend_from_slice(&values[start..start + len]);
32 },
33 )
34}
3536pub(super) fn build_extend_with_offset<T>(array: &ArrayData, offset: T) -> Extend
37where
38T: ArrowNativeType + Add<Output = T>,
39{
40let values = array.buffer::<T>(0);
41 Box::new(
42move |mutable: &mut _MutableArrayData, _, start: usize, len: usize| {
43 mutable
44 .buffer1
45 .extend(values[start..start + len].iter().map(|x| *x + offset));
46 },
47 )
48}
4950pub(super) fn extend_nulls<T: ArrowNativeType>(mutable: &mut _MutableArrayData, len: usize) {
51 mutable.buffer1.extend_zeros(len * size_of::<T>());
52}