crate::ix!();
pub fn build_large_skeleton(
aggregator_count: usize,
dispatch_count: usize,
leaf_count: usize,
) -> Skeleton {
let root_kind = if aggregator_count > 0 {
NodeKind::Aggregate
} else if dispatch_count > 0 {
NodeKind::Dispatch
} else {
NodeKind::LeafHolder
};
let mut root = SkeletonNodeBuilder::default()
.id(0)
.name("root") .original_key("root") .build(root_kind)
.unwrap();
let mut agg_left = aggregator_count;
let mut disp_left = dispatch_count;
let mut leaf_left = leaf_count;
match root_kind {
NodeKind::Aggregate => {
if agg_left > 0 { agg_left -= 1; }
},
NodeKind::Dispatch => {
if disp_left > 0 { disp_left -= 1; }
},
NodeKind::LeafHolder => {
if leaf_left > 0 { leaf_left -= 1; }
},
}
let mut nodes = vec![root];
let mut child_ids = Vec::new();
let mut next_id = 1u16;
for _ in 0..agg_left {
let node = SkeletonNodeBuilder::default()
.id(next_id)
.name(format!("Agg{}", next_id)) .original_key(format!("Agg{}", next_id)) .build(NodeKind::Aggregate)
.unwrap();
child_ids.push(next_id);
nodes.push(node);
next_id += 1;
}
for _ in 0..disp_left {
let node = SkeletonNodeBuilder::default()
.id(next_id)
.name(format!("Disp{}", next_id)) .original_key(format!("Disp{}", next_id)) .build(NodeKind::Dispatch)
.unwrap();
child_ids.push(next_id);
nodes.push(node);
next_id += 1;
}
for _ in 0..leaf_left {
let node = SkeletonNodeBuilder::default()
.id(next_id)
.name(format!("Leaf{}", next_id)) .original_key(format!("Leaf{}", next_id)) .build(NodeKind::LeafHolder)
.unwrap();
child_ids.push(next_id);
nodes.push(node);
next_id += 1;
}
if let Some(r) = nodes.get_mut(0) {
match r {
SkeletonNode::Aggregate { child_ids: cid, .. } => {
*cid = child_ids;
},
SkeletonNode::Dispatch { child_ids: cid, .. } => {
*cid = child_ids;
},
SkeletonNode::LeafHolder { .. } => { }
}
}
SkeletonBuilder::default()
.nodes(nodes)
.root_id(Some(0))
.build()
.unwrap()
}