vortex_array/arrays/repeated/array.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5
6use crate::ArrayRef;
7use crate::EmptyArrayData;
8use crate::array::ArrayParts;
9use crate::array_slots;
10use crate::arrays::Repeated;
11use crate::arrays::RepeatedArray;
12
13/// The child slots of a [`RepeatedArray`].
14#[array_slots(Repeated)]
15pub struct RepeatedSlots {
16 /// The array that is repeated.
17 #[slot(0)]
18 pub child: ArrayRef,
19}
20
21impl RepeatedArray {
22 /// Creates an array of `len` rows that repeats `child` end to end, without reading any values.
23 ///
24 /// Row `i` is row `i % child.len()` of `child`, so `len` need not be a multiple of the child's
25 /// length: the last repetition is cut short.
26 ///
27 /// Returns an error if `len` is non-zero and `child` is empty.
28 pub fn try_new(child: ArrayRef, len: usize) -> VortexResult<Self> {
29 let dtype = child.dtype().clone();
30 Self::try_from_parts(ArrayParts::new(
31 Repeated,
32 dtype,
33 len,
34 EmptyArrayData,
35 RepeatedSlots { child }.into_slots(),
36 ))
37 }
38}