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/make_bfs_friendly_skeleton_ok.rs ]
crate::ix!();

/// BFS with aggregator at level0, giving each aggregator 2 children at next level, etc.
/// If `depth=0`, empty. If final level => leaf_count = `density`.
pub fn make_bfs_friendly_skeleton_ok(
    depth: u8, 
    breadth: u8, 
    density: u8
) -> Skeleton {
    if depth == 0 {
        return SkeletonBuilder::default().build().unwrap();
    }

    let mut nodes = Vec::new();
    let mut queue = VecDeque::new();
    let mut next_id = 0u16;

    // root => aggregator
    let root = SkeletonNodeBuilder::default()
        .id(next_id)
        .name("rootBFS")
        .original_key("rootBFS")
        .build(NodeKind::Aggregate)
        .unwrap();
    nodes.push(root);
    queue.push_back(next_id);
    next_id += 1;

    let mut lvl = 1u8;
    let mut actual_breadth = breadth.max(1); // ensure at least 1
    while lvl < depth {
        let qlen = queue.len();
        // for each node in this BFS level, create children
        for _ in 0..qlen {
            if let Some(pid) = queue.pop_front() {
                if lvl == depth - 1 {
                    // final => turn node into LeafHolder with leaf_count
                    for n in nodes.iter_mut() {
                        if n.id() == pid {
                            n.set_leaf_count(density as u16);
                        }
                    }
                } else {
                    // aggregator => spawn up to 'actual_breadth' child aggregator
                    let mut cids = vec![];
                    for _ in 0..actual_breadth {
                        let cnode = SkeletonNodeBuilder::default()
                            .id(next_id)
                            .name(format!("Node{}", next_id))
                            .original_key(format!("Node{}", next_id))
                            .build(NodeKind::Aggregate)
                            .unwrap();
                        nodes.push(cnode);
                        cids.push(next_id);
                        queue.push_back(next_id);
                        next_id += 1;
                    }
                    // attach child_ids
                    for nd in nodes.iter_mut() {
                        if nd.id() == pid {
                            nd.set_child_ids(cids);
                            break;
                        }
                    }
                }
            }
        }
        lvl += 1;
    }

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