pub struct NodeNameNetwork<NodeName>{ /* private fields */ }Expand description
Node Name Network - Pure graph structure for node connections.
Represents the topology of a network without any data attached to nodes or edges. This is useful for graph algorithms that only need connectivity information.
§Type Parameters
NodeName: Node name type (must be Clone, Hash, Eq, Send, Sync, Debug)
Implementations§
Source§impl<NodeName> NodeNameNetwork<NodeName>
impl<NodeName> NodeNameNetwork<NodeName>
Sourcepub fn with_capacity(nodes: usize, edges: usize) -> Self
pub fn with_capacity(nodes: usize, edges: usize) -> Self
Create a new NodeNameNetwork with initial capacity.
Sourcepub fn add_node(&mut self, node_name: NodeName) -> Result<NodeIndex, String>
pub fn add_node(&mut self, node_name: NodeName) -> Result<NodeIndex, String>
Add a node to the network.
Returns an error if the node already exists.
Sourcepub fn add_edge(
&mut self,
n1: &NodeName,
n2: &NodeName,
) -> Result<EdgeIndex, String>
pub fn add_edge( &mut self, n1: &NodeName, n2: &NodeName, ) -> Result<EdgeIndex, String>
Add an edge between two nodes.
Returns an error if either node doesn’t exist.
Sourcepub fn node_index(&self, node_name: &NodeName) -> Option<NodeIndex>
pub fn node_index(&self, node_name: &NodeName) -> Option<NodeIndex>
Get the NodeIndex for a node name.
Sourcepub fn node_name(&self, node: NodeIndex) -> Option<&NodeName>
pub fn node_name(&self, node: NodeIndex) -> Option<&NodeName>
Get the node name for a NodeIndex.
Sourcepub fn rename_node(
&mut self,
old_name: &NodeName,
new_name: NodeName,
) -> Result<(), String>
pub fn rename_node( &mut self, old_name: &NodeName, new_name: NodeName, ) -> Result<(), String>
Rename an existing node.
Sourcepub fn node_names(&self) -> Vec<&NodeName>
pub fn node_names(&self) -> Vec<&NodeName>
Get all node names.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get the number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Get the number of edges.
Sourcepub fn graph(&self) -> &StableGraph<(), (), Undirected>
pub fn graph(&self) -> &StableGraph<(), (), Undirected>
Get a reference to the internal graph.
Sourcepub fn graph_mut(&mut self) -> &mut StableGraph<(), (), Undirected>
pub fn graph_mut(&mut self) -> &mut StableGraph<(), (), Undirected>
Get a mutable reference to the internal graph.
Warning: Directly modifying the internal graph can break the node-name-to-index mapping.
Sourcepub fn post_order_dfs(&self, root: &NodeName) -> Option<Vec<NodeName>>
pub fn post_order_dfs(&self, root: &NodeName) -> Option<Vec<NodeName>>
Sourcepub fn post_order_dfs_by_index(&self, root: NodeIndex) -> Vec<NodeIndex>
pub fn post_order_dfs_by_index(&self, root: NodeIndex) -> Vec<NodeIndex>
Perform a post-order DFS traversal starting from the given root NodeIndex.
Returns NodeIndex in post-order (children before parents, leaves first).
Sourcepub fn euler_tour_edges(
&self,
root: &NodeName,
) -> Option<Vec<(NodeIndex, NodeIndex)>>
pub fn euler_tour_edges( &self, root: &NodeName, ) -> Option<Vec<(NodeIndex, NodeIndex)>>
Perform an Euler tour traversal starting from the given root node.
Delegates to NamedGraph::euler_tour_edges.
Sourcepub fn euler_tour_edges_by_index(
&self,
root: NodeIndex,
) -> Vec<(NodeIndex, NodeIndex)>
pub fn euler_tour_edges_by_index( &self, root: NodeIndex, ) -> Vec<(NodeIndex, NodeIndex)>
Perform an Euler tour traversal starting from the given root NodeIndex.
Delegates to NamedGraph::euler_tour_edges_by_index.
Sourcepub fn euler_tour_vertices(&self, root: &NodeName) -> Option<Vec<NodeIndex>>
pub fn euler_tour_vertices(&self, root: &NodeName) -> Option<Vec<NodeIndex>>
Perform an Euler tour traversal and return the vertex sequence.
Delegates to NamedGraph::euler_tour_vertices.
Sourcepub fn euler_tour_vertices_by_index(&self, root: NodeIndex) -> Vec<NodeIndex>
pub fn euler_tour_vertices_by_index(&self, root: NodeIndex) -> Vec<NodeIndex>
Perform an Euler tour traversal and return the vertex sequence by NodeIndex.
Delegates to NamedGraph::euler_tour_vertices_by_index.
Sourcepub fn path_between(
&self,
from: NodeIndex,
to: NodeIndex,
) -> Option<Vec<NodeIndex>>
pub fn path_between( &self, from: NodeIndex, to: NodeIndex, ) -> Option<Vec<NodeIndex>>
Find the shortest path between two nodes using A* algorithm.
Since this is an unweighted graph, we use unit edge weights.
§Returns
Some(Vec<NodeIndex>) containing the path from from to to (inclusive),
or None if no path exists.
Sourcepub fn is_connected_subset(&self, nodes: &HashSet<NodeIndex>) -> bool
pub fn is_connected_subset(&self, nodes: &HashSet<NodeIndex>) -> bool
Check if a subset of nodes forms a connected subgraph.
Uses DFS to verify that all nodes in the subset are reachable from each other within the induced subgraph.
§Returns
true if the subset is connected (or empty), false otherwise.
Sourcepub fn steiner_tree_nodes(
&self,
terminals: &HashSet<NodeIndex>,
) -> HashSet<NodeIndex>
pub fn steiner_tree_nodes( &self, terminals: &HashSet<NodeIndex>, ) -> HashSet<NodeIndex>
Compute the Steiner tree nodes spanning a set of terminal nodes.
For tree graphs, the Steiner tree is the union of the unique paths from one terminal to every other terminal.
§Arguments
terminals- Terminal node indices to span
§Returns
The set of nodes in the minimal connected subtree spanning terminals.
§Examples
use std::collections::HashSet;
use tensor4all_treetn::NodeNameNetwork;
let mut net: NodeNameNetwork<String> = NodeNameNetwork::new();
let a = net.add_node("A".to_string()).unwrap();
let b = net.add_node("B".to_string()).unwrap();
let c = net.add_node("C".to_string()).unwrap();
net.add_edge(&"A".to_string(), &"B".to_string()).unwrap();
net.add_edge(&"B".to_string(), &"C".to_string()).unwrap();
let steiner = net.steiner_tree_nodes(&[a, c].into_iter().collect::<HashSet<_>>());
assert_eq!(steiner, [a, b, c].into_iter().collect());Sourcepub fn edges_to_canonicalize(
&self,
current_region: Option<&HashSet<NodeIndex>>,
target: NodeIndex,
) -> CanonicalizeEdges
pub fn edges_to_canonicalize( &self, current_region: Option<&HashSet<NodeIndex>>, target: NodeIndex, ) -> CanonicalizeEdges
Sourcepub fn edges_to_canonicalize_by_names(
&self,
target: &NodeName,
) -> Option<Vec<(NodeName, NodeName)>>
pub fn edges_to_canonicalize_by_names( &self, target: &NodeName, ) -> Option<Vec<(NodeName, NodeName)>>
Compute edges to canonicalize from leaves to target, returning node names.
This is similar to edges_to_canonicalize(None, target) but returns
(from_name, to_name) pairs instead of (NodeIndex, NodeIndex).
Useful for operations that work with two networks that have the same topology but different NodeIndex values (e.g., contract_zipup).
§Arguments
target- Target node name for the orthogonality center
§Returns
None if target node doesn’t exist, otherwise a vector of (from, to) pairs
where from is the node being processed and to is its parent (towards target).
Sourcepub fn edges_to_canonicalize_to_region(
&self,
target_region: &HashSet<NodeIndex>,
) -> CanonicalizeEdges
pub fn edges_to_canonicalize_to_region( &self, target_region: &HashSet<NodeIndex>, ) -> CanonicalizeEdges
Compute edges to canonicalize from leaves towards a connected region (multiple centers).
Given a set of target nodes forming a connected region, this function returns all edges (src, dst) where:
srcis a node outside the target regiondstis the next node towards the target region
The edges are ordered so that nodes farther from the target region are processed first (children before parents), which is the correct order for canonicalization.
§Arguments
target_region- Set of NodeIndex that forms the canonical center region (must be non-empty and connected)
§Returns
CanonicalizeEdges with all edges pointing towards the target region.
Returns empty edges if target_region is empty.
§Panics
Does not panic, but if target_region is disconnected, behavior is undefined (may return partial results).
Sourcepub fn edges_to_canonicalize_to_region_by_names(
&self,
target_region: &HashSet<NodeName>,
) -> Option<Vec<(NodeName, NodeName)>>
pub fn edges_to_canonicalize_to_region_by_names( &self, target_region: &HashSet<NodeName>, ) -> Option<Vec<(NodeName, NodeName)>>
Compute edges to canonicalize towards a region, returning node names.
This is similar to edges_to_canonicalize_to_region but takes and returns
node names instead of NodeIndex.
§Arguments
target_region- Set of node names that forms the canonical center region
§Returns
None if any target node doesn’t exist, otherwise Some(Vec<(from, to)>)
where edges point towards the target region.
Sourcepub fn same_topology(&self, other: &Self) -> bool
pub fn same_topology(&self, other: &Self) -> bool
Check if two networks have the same topology (same nodes and edges).
Trait Implementations§
Source§impl<NodeName> Clone for NodeNameNetwork<NodeName>
impl<NodeName> Clone for NodeNameNetwork<NodeName>
Source§fn clone(&self) -> NodeNameNetwork<NodeName>
fn clone(&self) -> NodeNameNetwork<NodeName>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<NodeName> Debug for NodeNameNetwork<NodeName>
impl<NodeName> Debug for NodeNameNetwork<NodeName>
Auto Trait Implementations§
impl<NodeName> Freeze for NodeNameNetwork<NodeName>
impl<NodeName> RefUnwindSafe for NodeNameNetwork<NodeName>where
NodeName: RefUnwindSafe,
impl<NodeName> Send for NodeNameNetwork<NodeName>
impl<NodeName> Sync for NodeNameNetwork<NodeName>
impl<NodeName> Unpin for NodeNameNetwork<NodeName>where
NodeName: Unpin,
impl<NodeName> UnsafeUnpin for NodeNameNetwork<NodeName>
impl<NodeName> UnwindSafe for NodeNameNetwork<NodeName>where
NodeName: UnwindSafe,
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more