capability_feature_measurement/
depth_breadth_density.rs

1// ---------------- [ File: capability-feature-measurement/src/depth_breadth_density.rs ]
2crate::ix!();
3
4/// We want to define a trait hierarchy for "measuring" each portion of a `GrowerTreeConfiguration`
5/// against arbitrary tree-like data structures (e.g., `Skeleton`, `StringSkeleton`, or others).
6///
7/// These traits let us measure or infer the real state of a tree structure, so that client code
8/// can compare "actual" vs. "expected" parameters in a generic way.
9///
10/// **Naming Conventions**:
11/// - Each trait is named `TreeXyzMeasurer`, where `Xyz` aligns with a portion of the config.
12/// - Each trait method is named `measure_tree_xyz(...)`.
13/// - Associated data types similarly use `TreeXyz...` naming, with no public fields.
14///   Instead, we rely on private fields with accessor methods as needed (`getset`/`derive_builder`).
15///
16/// **Implementation Strategy**:
17/// - For each data structure type (e.g., `Skeleton`, `StringSkeleton`), implement these traits
18///   to provide the correct measurements. 
19/// - Some parameters (like `leaf_granularity`, etc.) might be purely derived
20///   from config or environment, so the measurement method can return `None` or a default.
21
22/// ---------------------------------------------------------------------------
23/// 1) Depth
24/// ---------------------------------------------------------------------------
25
26/// Provides a way to measure the **maximum depth** of a tree-like structure.
27///
28/// Implementations might do BFS/DFS to compute the maximum path length from root to leaves.
29pub trait TreeDepthMeasurer {
30    /// Returns the overall depth of this tree structure (≥1 if any nodes, 0 if empty).
31    fn measure_tree_depth(&self) -> u8;
32}
33
34/// ---------------------------------------------------------------------------
35/// 2) Breadth (Baseline Child Count)
36/// ---------------------------------------------------------------------------
37
38/// Provides a way to measure child counts (breadth) for each node in a tree structure.
39pub trait TreeBreadthMeasurer {
40    /// Returns the child-count distribution across all nodes in the tree (one entry per node).
41    fn measure_tree_breadth_distribution(&self) -> Vec<u8>;
42}
43
44/// ---------------------------------------------------------------------------
45/// 3) Density (Leaf Variants or Leaf Count)
46/// ---------------------------------------------------------------------------
47
48/// Provides a way to measure "leaf variants" or `leaf_count` at each node.
49/// Some data structures track `leaf_count` explicitly; others might calculate it from subtrees.
50pub trait TreeDensityMeasurer {
51    /// Returns the leaf-count distribution across all nodes in the tree.
52    fn measure_tree_density_distribution(&self) -> Vec<u16>;
53}