Preorder serialization: `0u8, id(4)` for a leaf; `1u8, , ` for an internal node.
(&self, out: &mut Vec<u8>)
| 313 | pub fn prune(&self, keep: &impl Fn(u32) -> bool) -> Option<AggNode> { |
| 314 | match self { |
| 315 | AggNode::Leaf(id) => keep(*id).then_some(AggNode::Leaf(*id)), |
| 316 | AggNode::Internal(l, r) => match (l.prune(keep), r.prune(keep)) { |
| 317 | (Some(a), Some(b)) => Some(AggNode::Internal(Box::new(a), Box::new(b))), |
| 318 | (Some(a), None) | (None, Some(a)) => Some(a), |
| 319 | (None, None) => None, |
| 320 | }, |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | /// Preorder serialization: `0u8, id(4)` for a leaf; `1u8, <left>, <right>` for |
| 325 | /// an internal node. |
| 326 | fn put(&self, out: &mut Vec<u8>) { |
| 327 | match self { |
| 328 | AggNode::Leaf(id) => { |
| 329 | out.push(0); |
| 330 | out.extend_from_slice(&id.to_le_bytes()); |
no test coverage detected