Skip to content

Commit d39327e

Browse files
committed
Define child traversal once on ArrayRef via children_iter
children/nchildren/nth_child/named_children no longer need the encoding vtable: implement them directly on ArrayRef over a single children_iter helper (the non-None slots in order) and drop them from DynArrayData. Only children_names still dispatches, for VTable::child_name. Signed-off-by: "Joe Isaacs" <joe.isaacs@live.co.uk> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XbjnDVZQ9KqXgAAhxy9g7D
1 parent 44844aa commit d39327e

2 files changed

Lines changed: 16 additions & 52 deletions

File tree

vortex-array/src/array/erased.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,19 +685,26 @@ impl ArrayRef {
685685

686686
// ArrayVisitor delegation methods
687687

688+
/// Returns an iterator over the children of the array: its non-None slots in order.
689+
pub fn children_iter(&self) -> impl Iterator<Item = &ArrayRef> {
690+
self.0.slots.iter().filter_map(|s| s.as_ref())
691+
}
692+
688693
/// Returns the children of the array.
689694
pub fn children(&self) -> Vec<ArrayRef> {
690-
self.0.data.children(self)
695+
self.children_iter().cloned().collect()
691696
}
692697

693698
/// Returns the number of children of the array.
694699
pub fn nchildren(&self) -> usize {
695-
self.0.data.nchildren(self)
700+
self.children_iter().count()
696701
}
697702

698703
/// Returns the nth child of the array without allocating a Vec.
704+
///
705+
/// Returns `None` if the index is out of bounds.
699706
pub fn nth_child(&self, idx: usize) -> Option<ArrayRef> {
700-
self.0.data.nth_child(self, idx)
707+
self.children_iter().nth(idx).cloned()
701708
}
702709

703710
/// Returns the names of the children of the array.
@@ -707,7 +714,10 @@ impl ArrayRef {
707714

708715
/// Returns the array's children with their names.
709716
pub fn named_children(&self) -> Vec<(String, ArrayRef)> {
710-
self.0.data.named_children(self)
717+
self.children_names()
718+
.into_iter()
719+
.zip(self.children_iter().cloned())
720+
.collect()
711721
}
712722

713723
/// Returns the data buffers of the array.

vortex-array/src/array/mod.rs

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,9 @@ pub(crate) trait DynArrayData: 'static + private::Sealed + Send + Sync + Debug {
8080

8181
// --- Visitor methods (formerly in ArrayVisitor) ---
8282

83-
/// Returns the children of the array.
84-
fn children(&self, this: &ArrayRef) -> Vec<ArrayRef>;
85-
86-
/// Returns the number of children of the array.
87-
fn nchildren(&self, this: &ArrayRef) -> usize;
88-
89-
/// Returns the nth child of the array without allocating a Vec.
90-
///
91-
/// Returns `None` if the index is out of bounds.
92-
fn nth_child(&self, this: &ArrayRef, idx: usize) -> Option<ArrayRef>;
93-
9483
/// Returns the names of the children of the array.
9584
fn children_names(&self, this: &ArrayRef) -> Vec<String>;
9685

97-
/// Returns the array's children with their names.
98-
fn named_children(&self, this: &ArrayRef) -> Vec<(String, ArrayRef)>;
99-
10086
/// Returns the buffers of the array.
10187
fn buffers(&self, this: &ArrayRef) -> Vec<ByteBuffer>;
10288

@@ -267,42 +253,10 @@ impl<V: VTable> DynArrayData for ArrayData<V> {
267253
Ok(())
268254
}
269255

270-
fn children(&self, this: &ArrayRef) -> Vec<ArrayRef> {
271-
let view: ArrayView<'_, V> = unsafe { ArrayView::new_unchecked(this, &self.data) };
272-
view.slots().iter().filter_map(|s| s.clone()).collect()
273-
}
274-
275-
fn nchildren(&self, this: &ArrayRef) -> usize {
276-
let view: ArrayView<'_, V> = unsafe { ArrayView::new_unchecked(this, &self.data) };
277-
view.slots().iter().filter(|s| s.is_some()).count()
278-
}
279-
280-
fn nth_child(&self, this: &ArrayRef, idx: usize) -> Option<ArrayRef> {
281-
let view: ArrayView<'_, V> = unsafe { ArrayView::new_unchecked(this, &self.data) };
282-
view.slots()
283-
.iter()
284-
.filter_map(|s| s.as_ref())
285-
.nth(idx)
286-
.cloned()
287-
}
288-
289256
fn children_names(&self, this: &ArrayRef) -> Vec<String> {
290257
let view: ArrayView<'_, V> = unsafe { ArrayView::new_unchecked(this, &self.data) };
291-
view.slots()
292-
.iter()
293-
.filter(|s| s.is_some())
294-
.enumerate()
295-
.map(|(i, _)| V::child_name(view, i))
296-
.collect()
297-
}
298-
299-
fn named_children(&self, this: &ArrayRef) -> Vec<(String, ArrayRef)> {
300-
let view: ArrayView<'_, V> = unsafe { ArrayView::new_unchecked(this, &self.data) };
301-
view.slots()
302-
.iter()
303-
.filter_map(|s| s.as_ref())
304-
.enumerate()
305-
.map(|(i, child)| (V::child_name(view, i), child.clone()))
258+
(0..this.nchildren())
259+
.map(|i| V::child_name(view, i))
306260
.collect()
307261
}
308262

0 commit comments

Comments
 (0)