pub fn hierarchical_communities_result<N, E, Ix>(
graph: &Graph<N, E, Ix>,
linkage: &str,
) -> Vec<CommunityResult<N>>Expand description
Hierarchical community structure with standardized CommunityResult return type
This function provides the same functionality as hierarchical_communities but returns
a vector of standardized CommunityResult types that provide multiple ways to access
the community structure at each hierarchy level.
This algorithm starts with each node as its own community and iteratively merges communities to maximize modularity. It builds a dendrogram-like structure showing the hierarchy of communities.
§Arguments
graph- The graph to analyzelinkage- Linkage criterion (“single”, “complete”, “average”)
§Returns
- A vector of
CommunityResults representing different hierarchy levels
§Time Complexity
O(n³) for complete linkage, O(n² * m) for single linkage, where n is the number of nodes and m is the number of edges. The algorithm builds a complete dendrogram by iteratively merging communities based on the specified linkage criterion.
§Space Complexity
O(n²) for storing the distance matrix and the hierarchical structure at all levels.
§Example
use scirs2_graph::{Graph, hierarchical_communities_result};
let mut graph: Graph<i32, f64> = Graph::new();
// ... add nodes and edges ...
let results = hierarchical_communities_result(&graph, "average");
for (level, result) in results.iter().enumerate() {
println!("Level {}: {} communities", level, result.num_communities);
}