diff --git a/vortex-array/src/array/erased.rs b/vortex-array/src/array/erased.rs index c3dc2e0eed7..caa56ccbb40 100644 --- a/vortex-array/src/array/erased.rs +++ b/vortex-array/src/array/erased.rs @@ -685,29 +685,46 @@ impl ArrayRef { // ArrayVisitor delegation methods + /// Returns an iterator over the children of the array: its non-None slots in order. + pub fn children_iter(&self) -> impl Iterator { + self.0.slots.iter().filter_map(|s| s.as_ref()) + } + /// Returns the children of the array. pub fn children(&self) -> Vec { - self.0.data.children(self) + self.children_iter().cloned().collect() } /// Returns the number of children of the array. pub fn nchildren(&self) -> usize { - self.0.data.nchildren(self) + self.children_iter().count() } /// Returns the nth child of the array without allocating a Vec. + /// + /// Returns `None` if the index is out of bounds. pub fn nth_child(&self, idx: usize) -> Option { - self.0.data.nth_child(self, idx) + self.children_iter().nth(idx).cloned() } - /// Returns the names of the children of the array. + /// Returns the names of the children of the array: the slot names of the non-None slots + /// in order. pub fn children_names(&self) -> Vec { - self.0.data.children_names(self) + self.0 + .slots + .iter() + .enumerate() + .filter(|(_, s)| s.is_some()) + .map(|(slot_idx, _)| self.slot_name(slot_idx)) + .collect() } /// Returns the array's children with their names. pub fn named_children(&self) -> Vec<(String, ArrayRef)> { - self.0.data.named_children(self) + self.children_names() + .into_iter() + .zip(self.children_iter().cloned()) + .collect() } /// Returns the data buffers of the array. diff --git a/vortex-array/src/array/mod.rs b/vortex-array/src/array/mod.rs index 3eea66c6a68..e34accebfb2 100644 --- a/vortex-array/src/array/mod.rs +++ b/vortex-array/src/array/mod.rs @@ -80,23 +80,6 @@ pub(crate) trait DynArrayData: 'static + private::Sealed + Send + Sync + Debug { // --- Visitor methods (formerly in ArrayVisitor) --- - /// Returns the children of the array. - fn children(&self, this: &ArrayRef) -> Vec; - - /// Returns the number of children of the array. - fn nchildren(&self, this: &ArrayRef) -> usize; - - /// Returns the nth child of the array without allocating a Vec. - /// - /// Returns `None` if the index is out of bounds. - fn nth_child(&self, this: &ArrayRef, idx: usize) -> Option; - - /// Returns the names of the children of the array. - fn children_names(&self, this: &ArrayRef) -> Vec; - - /// Returns the array's children with their names. - fn named_children(&self, this: &ArrayRef) -> Vec<(String, ArrayRef)>; - /// Returns the buffers of the array. fn buffers(&self, this: &ArrayRef) -> Vec; @@ -267,35 +250,6 @@ impl DynArrayData for ArrayData { Ok(()) } - fn children(&self, this: &ArrayRef) -> Vec { - let view = unsafe { ArrayView::new_unchecked(this, &self.data) }; - (0..V::nchildren(view)).map(|i| V::child(view, i)).collect() - } - - fn nchildren(&self, this: &ArrayRef) -> usize { - let view = unsafe { ArrayView::new_unchecked(this, &self.data) }; - V::nchildren(view) - } - - fn nth_child(&self, this: &ArrayRef, idx: usize) -> Option { - let view = unsafe { ArrayView::new_unchecked(this, &self.data) }; - (idx < V::nchildren(view)).then(|| V::child(view, idx)) - } - - fn children_names(&self, this: &ArrayRef) -> Vec { - let view = unsafe { ArrayView::new_unchecked(this, &self.data) }; - (0..V::nchildren(view)) - .map(|i| V::child_name(view, i)) - .collect() - } - - fn named_children(&self, this: &ArrayRef) -> Vec<(String, ArrayRef)> { - let view = unsafe { ArrayView::new_unchecked(this, &self.data) }; - (0..V::nchildren(view)) - .map(|i| (V::child_name(view, i), V::child(view, i))) - .collect() - } - fn buffers(&self, this: &ArrayRef) -> Vec { let view = unsafe { ArrayView::new_unchecked(this, &self.data) }; (0..V::nbuffers(view)) diff --git a/vortex-array/src/array/vtable/mod.rs b/vortex-array/src/array/vtable/mod.rs index 344aac64a88..3078a6ae9f5 100644 --- a/vortex-array/src/array/vtable/mod.rs +++ b/vortex-array/src/array/vtable/mod.rs @@ -115,45 +115,6 @@ pub trait VTable: 'static + Clone + Sized + Send + Sync + Debug { buffers: &[BufferHandle], ) -> VortexResult>; - /// Returns the number of children in the array. - /// - /// The default counts non-None slots. - fn nchildren(array: ArrayView<'_, Self>) -> usize { - array.slots().iter().filter(|s| s.is_some()).count() - } - - /// Returns the child at the given index. - /// - /// The default returns the `idx`-th non-None slot. - /// - /// # Panics - /// Panics if `idx >= nchildren(array)`. - fn child(array: ArrayView<'_, Self>, idx: usize) -> ArrayRef { - array - .slots() - .iter() - .filter_map(|s| s.clone()) - .nth(idx) - .vortex_expect("child index out of bounds") - } - - /// Returns the name of the child at the given index. - /// - /// The default returns the slot name of the `idx`-th non-None slot. - /// - /// # Panics - /// Panics if `idx >= nchildren(array)`. - fn child_name(array: ArrayView<'_, Self>, idx: usize) -> String { - array - .slots() - .iter() - .enumerate() - .filter(|(_, s)| s.is_some()) - .nth(idx) - .map(|(slot_idx, _)| Self::slot_name(array, slot_idx)) - .vortex_expect("child_name index out of bounds") - } - /// Serialize encoding metadata into a byte buffer for IPC or file storage. /// /// Return `None` if the array cannot be serialized by this encoding. Buffers and children are diff --git a/vortex-array/src/arrays/patched/vtable/mod.rs b/vortex-array/src/arrays/patched/vtable/mod.rs index e36d426c0be..71b1775cbf4 100644 --- a/vortex-array/src/arrays/patched/vtable/mod.rs +++ b/vortex-array/src/arrays/patched/vtable/mod.rs @@ -138,16 +138,6 @@ impl VTable for Patched { with_empty_buffers(self, array, buffers) } - fn child(array: ArrayView<'_, Self>, idx: usize) -> ArrayRef { - match idx { - PatchedSlots::INNER => array.inner().clone(), - PatchedSlots::LANE_OFFSETS => array.lane_offsets().clone(), - PatchedSlots::PATCH_INDICES => array.patch_indices().clone(), - PatchedSlots::PATCH_VALUES => array.patch_values().clone(), - _ => vortex_panic!("invalid child index for PatchedArray: {idx}"), - } - } - fn serialize( array: ArrayView<'_, Self>, _session: &VortexSession, diff --git a/vortex-python/src/arrays/py/vtable.rs b/vortex-python/src/arrays/py/vtable.rs index 91eb97d1dff..5ec749d3a5f 100644 --- a/vortex-python/src/arrays/py/vtable.rs +++ b/vortex-python/src/arrays/py/vtable.rs @@ -92,18 +92,6 @@ impl VTable for PythonVTable { with_empty_buffers(self, array, buffers) } - fn nchildren(_array: ArrayView<'_, Self>) -> usize { - 0 - } - - fn child(_array: ArrayView<'_, Self>, idx: usize) -> ArrayRef { - vortex_panic!("PythonArray child index {idx} out of bounds") - } - - fn child_name(_array: ArrayView<'_, Self>, idx: usize) -> String { - vortex_panic!("PythonArray child_name index {idx} out of bounds") - } - fn serialize( _array: ArrayView<'_, Self>, _session: &VortexSession,