capability-feature-measurement 0.1.0

A Rust crate providing a trait-based system for measuring and evaluating complexity, branching, density, and configuration of tree-like data structures.
Documentation
// ---------------- [ File: capability-feature-measurement/src/weighted_branching.rs ]
crate::ix!();

/// ---------------------------------------------------------------------------
/// 5) Weighted Branching
/// ---------------------------------------------------------------------------

/// Weighted branching is about a **mean ± variance** approach for node child counts.
/// This trait should return a summary that can be used to compare with the config’s
/// desired mean and variance range.
pub trait TreeWeightedBranchingMeasurer {
    fn measure_tree_weighted_branching(&self) -> TreeWeightedBranchingStats;
}

/// Summarizes child-count distribution stats for weighted branching validation.
/// No public fields; use `getset` for read access.
#[derive(Debug, Clone, PartialEq, derive_builder::Builder, getset::Getters)]
#[builder(pattern = "owned", setter(into), build_fn(skip))]
#[getset(get = "pub")]
pub struct TreeWeightedBranchingStats {
    #[builder(default)]
    total_nodes_in_tree: usize,

    #[builder(default)]
    total_child_count_in_tree: usize,

    #[builder(default)]
    min_child_count_in_tree: u8,

    #[builder(default)]
    max_child_count_in_tree: u8,

    #[builder(default)]
    average_child_count_in_tree: f32,
}

impl Default for TreeWeightedBranchingStats {
    fn default() -> Self {
        Self {
            total_nodes_in_tree: 0,
            total_child_count_in_tree: 0,
            min_child_count_in_tree: 0,
            max_child_count_in_tree: 0,
            average_child_count_in_tree: 0.0,
        }
    }
}

impl TreeWeightedBranchingStatsBuilder {
    pub fn build(&self) -> Result<TreeWeightedBranchingStats, derive_builder::UninitializedFieldError> {
        let stats = TreeWeightedBranchingStats {
            total_nodes_in_tree: self.total_nodes_in_tree.unwrap_or_default(),
            total_child_count_in_tree: self.total_child_count_in_tree.unwrap_or_default(),
            min_child_count_in_tree: self.min_child_count_in_tree.unwrap_or_default(),
            max_child_count_in_tree: self.max_child_count_in_tree.unwrap_or_default(),
            average_child_count_in_tree: self.average_child_count_in_tree.unwrap_or_default(),
        };
        Ok(stats)
    }
}