Skip to main content

AnalyzeResult

Struct AnalyzeResult 

Source
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>

Source

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());
Source

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));
Source

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));
Source

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());
Source

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());
Source

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>

Source§

fn clone(&self) -> AnalyzeResult<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N: Debug + NodeConstraints> Debug for AnalyzeResult<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<N: NodeConstraints> Default for AnalyzeResult<N>

Source§

fn default() -> Self

Create a default empty AnalyzeResult (equivalent to AnalyzeResult::new()).

§Examples
use directed_graph::analyze::AnalyzeResult;
let result: AnalyzeResult<&str> = AnalyzeResult::default();
assert!(result.is_acyclic() && result.is_complete());

Auto Trait Implementations§

§

impl<N> Freeze for AnalyzeResult<N>

§

impl<N> RefUnwindSafe for AnalyzeResult<N>
where N: RefUnwindSafe,

§

impl<N> Send for AnalyzeResult<N>
where N: Send,

§

impl<N> Sync for AnalyzeResult<N>
where N: Sync,

§

impl<N> Unpin for AnalyzeResult<N>
where N: Unpin,

§

impl<N> UnsafeUnpin for AnalyzeResult<N>

§

impl<N> UnwindSafe for AnalyzeResult<N>
where N: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.