Expand `CUBE(a, b)` → all 2^N subsets.
(groups: &[Vec<ast::Expr>])
| 165 | |
| 166 | /// Expand `CUBE(a, b)` → all 2^N subsets. |
| 167 | fn 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 | /// |
no test coverage detected