Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions vortex-array/src/array/erased.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &ArrayRef> {
self.0.slots.iter().filter_map(|s| s.as_ref())
}

/// Returns the children of the array.
pub fn children(&self) -> Vec<ArrayRef> {
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<ArrayRef> {
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<String> {
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.
Expand Down
46 changes: 0 additions & 46 deletions vortex-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayRef>;

/// 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<ArrayRef>;

/// Returns the names of the children of the array.
fn children_names(&self, this: &ArrayRef) -> Vec<String>;

/// 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<ByteBuffer>;

Expand Down Expand Up @@ -267,35 +250,6 @@ impl<V: VTable> DynArrayData for ArrayData<V> {
Ok(())
}

fn children(&self, this: &ArrayRef) -> Vec<ArrayRef> {
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<ArrayRef> {
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<String> {
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<ByteBuffer> {
let view = unsafe { ArrayView::new_unchecked(this, &self.data) };
(0..V::nbuffers(view))
Expand Down
39 changes: 0 additions & 39 deletions vortex-array/src/array/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,45 +115,6 @@ pub trait VTable: 'static + Clone + Sized + Send + Sync + Debug {
buffers: &[BufferHandle],
) -> VortexResult<ArrayParts<Self>>;

/// 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
Expand Down
10 changes: 0 additions & 10 deletions vortex-array/src/arrays/patched/vtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 0 additions & 12 deletions vortex-python/src/arrays/py/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading