pub struct DependencyGraph { /* private fields */ }Expand description
A directed dependency graph for packages.
Nodes are package names; edges point from a package to its dependencies. Supports reverse dependency lookup, circular dependency detection, and dependency depth calculation.
Implementations§
Source§impl DependencyGraph
impl DependencyGraph
Sourcepub fn add_package(&mut self, name: &str)
pub fn add_package(&mut self, name: &str)
Add a package node to the graph (with no dependencies initially).
Sourcepub fn add_dependency(&mut self, package: &str, dependency: &str)
pub fn add_dependency(&mut self, package: &str, dependency: &str)
Add a dependency edge: package depends on dependency.
Both nodes are created if they do not already exist.
Sourcepub fn find_reverse_deps(&self, package: &str) -> Vec<String>
pub fn find_reverse_deps(&self, package: &str) -> Vec<String>
Find all packages that depend on the given package (reverse dependencies).
Sourcepub fn detect_circular_deps(&self) -> Vec<Vec<String>>
pub fn detect_circular_deps(&self) -> Vec<Vec<String>>
Detect circular dependencies in the graph via DFS.
Returns a list of cycles, where each cycle is a list of package names forming the cycle. An empty result means no cycles exist.
Sourcepub fn dependency_depth(&self, package: &str) -> usize
pub fn dependency_depth(&self, package: &str) -> usize
Compute the dependency depth of a package.
The depth is the longest path from any root (a package with no reverse dependencies) to this package. Returns 0 if the package is a root or is not in the graph.
Sourcepub fn find_roots(&self) -> Vec<String>
pub fn find_roots(&self) -> Vec<String>
Find root nodes (packages that no other package depends on).
Sourcepub fn package_count(&self) -> usize
pub fn package_count(&self) -> usize
Return the total number of packages in the graph.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Return the total number of dependency edges.
Sourcepub fn dependencies(&self, package: &str) -> Option<&[String]>
pub fn dependencies(&self, package: &str) -> Option<&[String]>
Return the direct dependencies of a package.