pub struct AnalyzeResult<N: NodeConstraints> { /* private fields */ }Expand description
The result of a directed graph analysis, containing undefined nodes, self-loop nodes and detected cycles.
This struct aggregates all key insights from a graph analysis:
- Nodes that are referenced as targets but do not exist in the graph (undefined nodes)
- Nodes that have an edge pointing to themselves (self-loop nodes)
- All unique cycles detected in the graph (standardized to avoid duplicates)
It also provides helper methods to check graph properties (acyclic, complete).
Implementations§
Source§impl<N: NodeConstraints> AnalyzeResult<N>
impl<N: NodeConstraints> AnalyzeResult<N>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty AnalyzeResult with no undefined nodes, self-loops or cycles.
§Examples
use directed_graph::analyze::AnalyzeResult;
let result: AnalyzeResult<u32> = AnalyzeResult::new();
assert!(result.undefined_nodes().is_empty());
assert!(result.selfloop_nodes().is_empty());
assert!(result.is_acyclic());Sourcepub fn undefined_nodes(&self) -> &HashSet<N>
pub fn undefined_nodes(&self) -> &HashSet<N>
Get an immutable reference to the set of undefined nodes in the graph.
Undefined nodes are target nodes that are referenced by an edge but do not exist as a source node in the graph (orphaned edge targets).
§Returns
A reference to a HashSet<N> containing all undefined nodes.
§Examples
use directed_graph::{DirectedGraph, analyze::analyze_digraph};
let mut graph = DirectedGraph::new();
graph.add_node(1, vec![2]); // 2 is an undefined node
let result = analyze_digraph(&graph);
assert!(result.undefined_nodes().contains(&2));Sourcepub fn selfloop_nodes(&self) -> &HashSet<N>
pub fn selfloop_nodes(&self) -> &HashSet<N>
Get an immutable reference to the set of self-loop nodes in the graph.
Self-loop nodes are nodes that have an outgoing edge pointing to themselves (e.g., A -> A).
§Returns
A reference to a HashSet<N> containing all self-loop nodes.
§Examples
use directed_graph::{DirectedGraph, analyze::analyze_digraph};
let mut graph = DirectedGraph::new();
graph.add_node(1, vec![1]); // 1 is a self-loop node
let result = analyze_digraph(&graph);
assert!(result.selfloop_nodes().contains(&1));Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if the graph is complete (no undefined nodes).
A complete graph in this context means every target node referenced by an edge exists as a source node in the graph (no orphaned edge targets).
§Returns
true if there are no undefined nodes, false otherwise.
§Examples
use directed_graph::{DirectedGraph, analyze::analyze_digraph};
let mut graph = DirectedGraph::new();
graph.add_node(1, vec![2]);
let result = analyze_digraph(&graph);
assert!(!result.is_complete());
graph.add_node(2, vec![]);
let result = analyze_digraph(&graph);
assert!(result.is_complete());Sourcepub fn is_acyclic(&self) -> bool
pub fn is_acyclic(&self) -> bool
Check if the graph is acyclic (no cycles detected).
An acyclic directed graph (DAG) has no paths that start and end at the same node.
Self-loops are considered cycles and will make this return false.
§Returns
true if no cycles are detected, false otherwise.
§Examples
use directed_graph::{DirectedGraph, analyze::analyze_digraph};
let mut graph = DirectedGraph::new();
graph.add_node(1, vec![2]);
graph.add_node(2, vec![3]);
let result = analyze_digraph(&graph);
assert!(result.is_acyclic());
graph.add_node(3, vec![1]); // Creates a cycle 1->2->3->1
let result = analyze_digraph(&graph);
assert!(!result.is_acyclic());Sourcepub fn get_elementary_cycles(&self) -> &Vec<Vec<N>>
pub fn get_elementary_cycles(&self) -> &Vec<Vec<N>>
Get an immutable reference to all unique cycles detected in the graph.
Cycles are standardized to avoid duplicate representations (e.g., 1->2->3 and 2->3->1 are the same cycle)
and sorted for consistency. Self-loops are represented as a single-element vector (e.g., vec![1]).
§Returns
A reference to a Vec<Vec<N>> where each inner vector is a unique standardized cycle.
§Examples
use directed_graph::{DirectedGraph, analyze::analyze_digraph};
let mut graph = DirectedGraph::new();
graph.add_node(1, vec![2]);
graph.add_node(2, vec![3]);
graph.add_node(3, vec![1]);
let result = analyze_digraph(&graph);
assert_eq!(result.get_elementary_cycles(), &vec![vec![1, 2, 3]]);Trait Implementations§
Source§impl<N: Clone + NodeConstraints> Clone for AnalyzeResult<N>
impl<N: Clone + NodeConstraints> Clone for AnalyzeResult<N>
Source§fn clone(&self) -> AnalyzeResult<N>
fn clone(&self) -> AnalyzeResult<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more