1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Unified Query Algebra
//
// Copyright (c) 2023-2026 Cognica, Inc.
//
use super::OwnedScalarExpr;
/// Moves immediate scalar children in copy order without copying their payloads or allocating a work queue. Unvisited children and the original parent containers remain owned until exhaustion or iterator destruction.
pub struct OwnedScalarChildren {
parent: Option<OwnedScalarExpr>,
next: usize,
end: usize,
}
impl OwnedScalarExpr {
/// Consume the parent while moving its children. Selecting the final child immediately destroys the now-empty parent; abandoning the iterator destroys the unvisited children as well.
pub fn into_children(self) -> OwnedScalarChildren {
let end = self.child_count();
OwnedScalarChildren {
parent: (end != 0).then_some(self),
next: 0,
end,
}
}
}
impl Iterator for OwnedScalarChildren {
type Item = OwnedScalarExpr;
fn next(&mut self) -> Option<Self::Item> {
let parent = self.parent.as_mut()?;
let child = parent.take_child(self.next);
self.next += 1;
if self.next == self.end {
self.parent = None;
}
Some(child)
}
fn size_hint(&self) -> (usize, Option<usize>) {
let remaining = self.end - self.next;
(remaining, Some(remaining))
}
}
impl ExactSizeIterator for OwnedScalarChildren {}
impl std::iter::FusedIterator for OwnedScalarChildren {}