MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / expand_cube

Function expand_cube

nodedb-sql/src/planner/grouping_sets.rs:167–181  ·  view source on GitHub ↗

Expand `CUBE(a, b)` → all 2^N subsets.

(groups: &[Vec<ast::Expr>])

Source from the content-addressed store, hash-verified

165
166/// Expand `CUBE(a, b)` → all 2^N subsets.
167fn expand_cube(groups: &[Vec<ast::Expr>]) -> Vec<Vec<&ast::Expr>> {
168 let atoms: Vec<&ast::Expr> = groups.iter().flat_map(|g| g.iter()).collect();
169 let n = atoms.len();
170 let count = 1usize << n;
171 let mut sets: Vec<Vec<&ast::Expr>> = Vec::with_capacity(count);
172 // Enumerate all bitmasks from (all-present) down to 0 (empty).
173 for mask in (0..count).rev() {
174 let set: Vec<&ast::Expr> = (0..n)
175 .filter(|i| (mask >> i) & 1 == 1)
176 .map(|i| atoms[i])
177 .collect();
178 sets.push(set);
179 }
180 sets
181}
182
183/// Resolve the canonical index for a `GROUPING(col)` argument.
184///

Callers 1

expand_group_byFunction · 0.85

Calls 4

collectMethod · 0.80
iterMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected