capability-skeleton-mock 0.1.0

A Rust crate for constructing and managing hierarchical skeleton structures with diverse node types, enabling advanced testing and simulation scenarios.
Documentation
// ---------------- [ File: capability-skeleton-mock/src/build_large_skeleton.rs ]
crate::ix!();

/// Builds a skeleton with the specified number of aggregator, dispatch, and leaf nodes.
/// The root node’s kind is determined automatically. If `aggregator_count>0`, the root is aggregator,
/// etc. Then we SUBTRACT 1 from that category’s count (so we don’t double‐count the root).
///
/// This ensures the final aggregator fraction matches aggregator_count / (aggregator_count + dispatch_count).
///
/// All those aggregator/dispatch/leaf children are attached to the root’s child_ids (so BFS is basically 2 levels).
pub fn build_large_skeleton(
    aggregator_count: usize,
    dispatch_count: usize,
    leaf_count: usize,
) -> Skeleton {
    // Decide root kind:
    let root_kind = if aggregator_count > 0 {
        NodeKind::Aggregate
    } else if dispatch_count > 0 {
        NodeKind::Dispatch
    } else {
        NodeKind::LeafHolder
    };

    // Build the root node
    let mut root = SkeletonNodeBuilder::default()
        .id(0)
        .name("root")                       // CHANGED
        .original_key("root")               // CHANGED
        .build(root_kind)
        .unwrap();

    // We subtract 1 from whichever category is used for the root
    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;

    // Add aggregator nodes
    for _ in 0..agg_left {
        let node = SkeletonNodeBuilder::default()
            .id(next_id)
            .name(format!("Agg{}", next_id))         // CHANGED
            .original_key(format!("Agg{}", next_id)) // CHANGED
            .build(NodeKind::Aggregate)
            .unwrap();
        child_ids.push(next_id);
        nodes.push(node);
        next_id += 1;
    }
    // Add dispatch nodes
    for _ in 0..disp_left {
        let node = SkeletonNodeBuilder::default()
            .id(next_id)
            .name(format!("Disp{}", next_id))        // CHANGED
            .original_key(format!("Disp{}", next_id))// CHANGED
            .build(NodeKind::Dispatch)
            .unwrap();
        child_ids.push(next_id);
        nodes.push(node);
        next_id += 1;
    }
    // Add leaf nodes
    for _ in 0..leaf_left {
        let node = SkeletonNodeBuilder::default()
            .id(next_id)
            .name(format!("Leaf{}", next_id))        // CHANGED
            .original_key(format!("Leaf{}", next_id))// CHANGED
            .build(NodeKind::LeafHolder)
            .unwrap();
        child_ids.push(next_id);
        nodes.push(node);
        next_id += 1;
    }

    // If root is aggregator/dispatch, set its child_ids:
    // If it's a leaf, we do nothing so BFS sees only one node at level0
    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 { .. } => { /* do nothing */ }
        }
    }

    SkeletonBuilder::default()
        .nodes(nodes)
        .root_id(Some(0))
        .build()
        .unwrap()
}